Skip to content

need to use .cjs/.mjs file extensions #5020

@dynst

Description

@dynst

Ethers Version

6.15.0

Search Terms

No response

Describe the Problem

ethers.js/package.json

Lines 38 to 39 in 9fd9d41

"import": "./lib.esm/index.js",
"default": "./lib.commonjs/index.js"

Running Node.js v20.18.0, when you import a file that ends in .js, and the nearest package.json doesn't say type: "module" (and the package.json in ethers doesn't), it gets parsed as CommonJS.

So it just chokes with a SyntaxError when it sees ESM syntax.

Either ESM files have to end in .mjs, or "type" has to be added to package.json and all CommonJS files have to end in .cjs.

Code Snippet

`import ethers from 'ethers'`

Contract ABI

Errors

Environment

No response

Environment (Other)

No response

Metadata

Metadata

Assignees

Labels

investigateUnder investigation and may be a bug.v6Issues regarding v6

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions