Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load metaplex #553

Open
georgewslee opened this issue Jul 1, 2024 · 4 comments
Open

Failed to load metaplex #553

georgewslee opened this issue Jul 1, 2024 · 4 comments

Comments

@georgewslee
Copy link

I have a file named testMetaplex.cjs with just one line of code:
const Metaplex = require("@metaplex-foundation/js");
Running on Node.js v20.15.0.

my npm list:
├── @metaplex-foundation/[email protected]
├── @raydium-io/[email protected]
├── @solana/[email protected]
├── @solana/[email protected]
└── @solana/[email protected]

and I get the following error:
...\node_modules@metaplex-foundation\mpl-candy-guard\dist\src\generated\instructions\mint.js:27
const splToken = __importStar(require("@solana/spl-token"));

Error [ERR_REQUIRE_ESM]: require() of ES Module ...\node_modules@solana\spl-token\lib\cjs\index.js from ...\node_modules@metaplex-foundation\mpl-candy-guard\dist\src\generated\instructions\mint.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 ...\node_modules@solana\spl-token\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

at Object.<anonymous> (...\node_modules\@metaplex-foundation\mpl-candy-guard\dist\src\generated\instructions\mint.js:27:31) {

code: 'ERR_REQUIRE_ESM'
}

Is it possible to use metaplex via cjs?

@FilipeAleixo
Copy link

FilipeAleixo commented Jul 1, 2024

Same issue on Mac M3.

node 18.9.1, pnpm 8.8.0

Forcing @solana/spl-token to version 0.4.6 solved my issue. on pnpm-lock.yaml it set that package to 0.4.7 when I did a fresh install and it broke.

@youngqqcn
Copy link

same issue with 0.4.7

"dependencies": {
    "@solana/spl-token": "^0.4.7",
    "@solana/web3.js": "^1.94.0",
    "@types/node": "^20.14.9",
    "tslint": "^6.1.3",
    "typescript": "^5.5.3"
  },
/usr/lib/node_modules/ts-node/dist/index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/yqq/fansland/fansland_ai/demos/spl-token-use/node_modules/@solana/spl-token/lib/cjs/index.js from /home/yqq/fansland/fansland_ai/demos/spl-token-use/src/index.ts 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 /home/yqq/fansland/fansland_ai/demos/spl-token-use/node_modules/@solana/spl-token/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at require.extensions.<computed> [as .js] (/usr/lib/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/home/yqq/fansland/fansland_ai/demos/spl-token-use/src/index.ts:3:21)
    at m._compile (/usr/lib/node_modules/ts-node/dist/index.js:857:29) {
  code: 'ERR_REQUIRE_ESM'
}
error Command failed with exit code 1.

@ordas21
Copy link

ordas21 commented Jul 3, 2024

same issue for me

@georgewslee
Copy link
Author

georgewslee commented Jul 6, 2024

I have a file named testMetaplex.cjs with just one line of code: const Metaplex = require("@metaplex-foundation/js"); Running on Node.js v20.15.0.

my npm list: ├── @metaplex-foundation/[email protected] ├── @raydium-io/[email protected] ├── @solana/[email protected] ├── @solana/[email protected] └── @solana/[email protected]

and I get the following error: ...\node_modules@metaplex-foundation\mpl-candy-guard\dist\src\generated\instructions\mint.js:27 const splToken = __importStar(require("@solana/spl-token"));

Error [ERR_REQUIRE_ESM]: require() of ES Module ...\node_modules@solana\spl-token\lib\cjs\index.js from ...\node_modules@metaplex-foundation\mpl-candy-guard\dist\src\generated\instructions\mint.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 ...\node_modules@solana\spl-token\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

at Object.<anonymous> (...\node_modules\@metaplex-foundation\mpl-candy-guard\dist\src\generated\instructions\mint.js:27:31) {

code: 'ERR_REQUIRE_ESM' }

Is it possible to use metaplex via cjs?

I ended up using @metaplex-foundation/umi-bundle-defaults and @metaplex-foundation/mpl-token-metadata instead.
My intention was just to get token metadata, given a token address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants