Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Failed to load metaplex #553

@georgewslee

Description

@georgewslee

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions