solana-labs / solana-program-library

A collection of Solana programs maintained by Solana Labs
https://solanalabs.com
Apache License 2.0
3.48k stars 2.05k forks source link

Question (Bug?): Upgrade of @solana/spl-token from 0.4.6->0.4.7 throws ERR_REQUIRE_ESM error #6958

Closed alexolaruhf closed 2 months ago

alexolaruhf commented 3 months ago

Has anyone else noticed an error such as the one below when upgrading the @solana/spl-token package from 0.4.6 to 0.4.7?

Just downgrading the version of the package to 0.4.6 fixed the error for us.

We are using Node v18.20.3

Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/src/app/node_modules/@alphaledger/solana-lib/node_modules/@solana/spl-token/lib/cjs/index.js from /usr/src/app/node_modules/@alphaledger/solana-lib/dist/client/operations/utils.js not supported.

index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.

Instead either rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /usr/src/app/node_modules/@alphaledger/solana-lib/node_modules/@solana/spl-token/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
kewlfft commented 3 months ago

Same here, it seems to be related to @solana/spl-token-group downgraded from 0.0.4 to 0.0.3 in the npm package.

buffalojoec commented 3 months ago

Yeah, looks like @kewlfft is correct.

The 0.0.3 release for @solana/spl-token-group was deprecated, citing CommonJS build errors.

Screenshot 2024-07-02 at 11 11 24 PM

Version 0.4.6 for @solana/spl-token was using th correct version (0.0.4), but it looks like we missed a commit somewhere to bump versions, and the dependencies for @solana/spl-token fell behind.


I'm happy to reconcile this issue, but it would help if either of you guys could paste in some code that would help me reproduce - so I can accurately confirm a fix. Thanks!

ordas21 commented 3 months ago

can confirm the same even when downgrading to 0.4.6 I am having this issue, but I am unsure if its related to other packages utilize 0.4.7

buffalojoec commented 2 months ago

Should be all set, guys. Upgrade to 0.4.8.