@@ -51,11 +51,49 @@ engine-strict=true
5151# Options only include those that are valid `NODE_OPTIONS`.
5252# See: https://nodejs.org/api/cli.html#cli_node_options_options
5353#
54- # Allow top-level `await` calls so that webpack.config.mjs can await CJS imports.
55- # Allow JSON files to be imported in .mjs files.
56- # Allow automatic extension resolution as well as importing index.js from directories like source code can (e.g. `import file from './file'` instead of './file.js', and `import Utils from './utils'` instead of './utils/index.js').
57- # Allow the use of `import.meta.resolve` to use file paths to generate import-safe URLs (different from browser-safe URLs).
58- node-options = ' --experimental-top-level-await --experimental-json-modules --experimental-specifier-resolution=node --experimental-import-meta-resolve'
54+ # Notable ones include:
55+ #
56+ # * --experimental-top-level-await
57+ # Allow top-level `await` calls so that webpack.config.mjs can await CJS imports.
58+ #
59+ #
60+ # * --experimental-json-modules
61+ # Allow JSON files to be imported in .mjs files.
62+ #
63+ #
64+ # * --experimental-import-meta-resolve
65+ # Allow the use of `import.meta.resolve` to use file paths to generate import-safe URLs (different from browser-safe URLs).
66+ #
67+ #
68+ # * --experimental-specifier-resolution=node
69+ # Allow automatic extension resolution as well as importing index.js from directories like source code can
70+ # e.g. `import file from './file'` instead of './file.js', and `import Utils from './utils'` instead of './utils/index.js'.
71+ # Note: This will cause some `npx` commands to fail if the executables don't have a file extension on them (e.g. `npx tsc`).
72+ # Relatedly, if using a different script runner/node module loader, e.g. `ts-node` to run TypeScript files, then they will
73+ # sometimes fail as well b/c they'll either be shell scripts, will need their custom module loader (which won't work b/c we
74+ # overrode it with this flag), or their loaders depending on files being translated to CommonJS before being executed (likely in RAM
75+ # by their custom loader and/or NodeJS itself).
76+ # This can be fixed in your own code by making it executable and adding a shebang, e.g.
77+ # #!/usr/bin/env -S node
78+ # #!/usr/bin/env -S npx
79+ # #!/usr/bin/env -S npx ts-node
80+ # For example, to use `ts-node` (for running TypeScript files from the CLI without having to compile them into JavaScript first),
81+ # then they recommend running via either:
82+ # 1. Using ts-node directly: `ts-node file.ts`
83+ # 2. Using normal node command: ESM: `node --loader ts-node/esm file.ts` - CJS: `node -r ts-node/register file.ts`
84+ # 3. Just run the file directly: Use a shebang like above (See: https://github.com/TypeStrong/ts-node/issues/639)
85+ # 4. Add `--loader ts-node/(register|esm)` to `node-options` here (forces all node commands to run with `ts-node`, even `npx`)
86+ # n. TL;DR - Check out this issue for a full analysis of way to run `ts-node`: https://github.com/TypeStrong/ts-node/issues/995
87+ # But since `ts-node` uses its own module loader, we cannot set `--experimental-specifier-resolution=node` in `node-options`
88+ # b/c it requires its own loader.
89+ # Finally, for `ts-node`, if package.json uses `type: module`, then `ts-node` must use `module: ESNext` as well.
90+ #
91+ #
92+ # * --no-warnings / --redirect-warnings=<file>
93+ # Removes warnings from STDERR or redirects them to <file>.
94+ # If you want to use ts-node by default for all files, then this will be necessary to reduce console noise:
95+ # --loader=ts-node/register --no-warnings
96+ node-options = ' --experimental-top-level-await --experimental-json-modules --experimental-import-meta-resolve'
5997
6098
6199# For some reason, `npm run` doesn't use the default shell,
0 commit comments