Skip to content

Should ESM-only packages use the import or default condition? #4739

Answered by aduh95
bluwy asked this question in Q&A
Discussion options

You must be logged in to vote

Option 3:

{
  "type": "module",
  "exports": {
    ".":  "./index.js"
  }
}

That would be the one I'd use, it's equivalent to option 2 for the error message and also simpler.

But currently I'm doing option 1 because other environments can easily know if a package is import-able by only resolving the exports object without hitting the fs.

I'm not sure what you mean by that, in Node.js "every" JS files are "importable", as it is possible to import both ESM and CJS. The fact that you list it in the "import" conditions tells nothing to the tool you're using what format the file is (i.e. "import": "./file.cjs" would be a valid export, and file.cjs would be interpreted as a CJS file).

Replies: 0 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@bluwy
Comment options

Answer selected by bluwy
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants