How to use ESM for Forge instead of CJS?

@ibuchanan , the repo you posted for webtrigger auth uses a simple import for jose:

import { jwtVerify } from "jose";

when i try to deploy something using that, i get:

Error: TypeScript errors in the app caused the bundling to fail. Fix the errors listed below before rerunning the command. [tsl] ERROR in /home/ltheisen/egit/lucastheisen-learn-atlassian-forge-assets-import-app/src/resolvers/webtrigger-auth.ts(4,47)
      TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("jose")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/home/ltheisen/egit/lucastheisen-learn-atlassian-forge-assets-import-app/package.json'.

This error makes sense given that jose does not support CommonJS style import. Im wondering what magic i might have missed that allows you to do this… Is there a way to get Forge apps to be ESM instead of CommonJS?

I had to write an abstraction that should work for this, but it would be way nicer to embrace ESM if its possible.

@LucasTheisen,

I’ve been doing a lot of this with Rovo Dev doing the heavy lifting, so I asked it, and the following should do the trick:

  • Add "type": "module" to the Forge app’s package.json
  • Set "module": "ESNext"(or "ES2022") in tsconfig.json
  • Set "moduleResolution": "node" in tsconfig.json

I’ll be on vacation for the next couple weeks, but I’m planning to do some exploration with this bundler EAP upon my return:

I hit exactly the same Zod problem that made me aware of the EAP in the first place: