RevenueCat / purchases-capacitor

Capacitor in-app purchases and subscriptions made easy.
MIT License
137 stars 14 forks source link

Compile error: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. #290

Closed 0xymoro closed 1 month ago

0xymoro commented 1 month ago

On React & Nextjs, and finding that the package doesn't play nice. I tried to import from the documentation but seeing this, would love some help.

(node:40339) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. ⨯ /Users//Dev//node_modules/@revenuecat/purchases-typescript-internal-esm/dist/index.js:1 export * from './errors'; ^^^^^^

SyntaxError: Unexpected token 'export' at wrapSafe (node:internal/modules/cjs/loader:1427:18) at Module._compile (node:internal/modules/cjs/loader:1449:20) at Module._extensions..js (node:internal/modules/cjs/loader:1588:10) at Module.load (node:internal/modules/cjs/loader:1282:32) at Module._load (node:internal/modules/cjs/loader:1098:12) at TracingChannel.traceSync (node:diagnostics_channel:315:14) at wrapModuleLoad (node:internal/modules/cjs/loader:215:24) at Module.require (node:internal/modules/cjs/loader:1304:12)

RCGitBot commented 1 month ago

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

rglanz-rc commented 1 month ago

Hi, This is more of a node.js/javascript thing. If you add this to your package.json file, it will tell your entire project to look for JS modules (and you'll need to use import instead of require).

{
    "type": "module"
}
0xymoro commented 1 month ago

I figured it out, it was a little deeper than just type module (which was there). I had not added it to the nextjs transpile, and I think it didn't play nice with some other project setup.