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

Updating docs on type="commonjs" #32

Open
frehner opened this issue Oct 31, 2023 · 0 comments
Open

Updating docs on type="commonjs" #32

frehner opened this issue Oct 31, 2023 · 0 comments

Comments

@frehner
Copy link
Owner

frehner commented Oct 31, 2023

As per this new update to NodeJS:

The new flag --experimental-detect-module can be used to automatically run ES modules when their syntax can be detected. For “ambiguous” files, which are .js or extensionless files with no package.json with a type field, Node.js will parse the file to detect ES module syntax; if found, it will run the file as an ES module, otherwise it will run the file as a CommonJS module. The same applies to string input via --eval or STDIN.

We hope to make detection enabled by default in a future version of Node.js. Detection increases startup time, so we encourage everyone — especially package authors — to add a type field to package.json, even for the default "type": "commonjs". The presence of a type field, or explicit extensions such as .mjs or .cjs, will opt out of detection.

https://nodejs.org/en/blog/release/v21.1.0#automatically-detect-and-run-esm-syntax

We should add a link to that document and explain that having type="commonjs" will ensure faster parsing time when using the auto-module-detection flag.

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

1 participant