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

Improved module specification in package.json #2921

Closed
wants to merge 1 commit into from

Conversation

benmccann
Copy link

It's not really valid according to the spec to not have a main field. If you are distributing multiple versions like CJS and ESM you can specify one in main and the ESM in module, but you shouldn't ever really have a missing main field. If the main is an ESM file you can simply specify "type": "module"

@hediet hediet requested a review from alexdima January 27, 2022 11:26
@hediet
Copy link
Member

hediet commented Jan 27, 2022

Makes sense. CI fails however, so it seems there is a difference indeed.

@hediet hediet removed the request for review from alexdima January 27, 2022 11:29
@bluwy
Copy link

bluwy commented Jan 27, 2022

It's not really valid according to the spec to not have a main field

I'm not sure if this is true. main should be CJS only, regardless of type: module. Nodejs only supports ESM entrypoints via the exports field. module is used by bundlers only.

@benmccann
Copy link
Author

main should be CJS only, regardless of type: module

Really? Do you have a reference for that? The docs for "type" seem to align with how I believe it works https://nodejs.org/api/packages.html#type

I'll need to push an update to the PR though. Adding "type": "module" means we need to switch the build scripts to ESM

@bluwy
Copy link

bluwy commented Jan 27, 2022

According to https://nodejs.org/api/packages.html#main, it's used for require() only, so having main as ESM doesn't sound right. I was actually working on a PR too to simply add a package.json of type:module into the release /esm folder 😬 maybe we can go with that (#2923)

@benmccann
Copy link
Author

Those docs are rather misleading. I sent a PR to the Node docs to clarify: nodejs/node#41720

But this PR would require too much work for me to proceed with. I'd need to convert the whole codebase to ESM to add "type": "module" and I didn't realize how many other places there's CJS code still, so I'll go ahead and close this

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

Successfully merging this pull request may close these issues.

3 participants