You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 2, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 2, 2023. It is now read-only.
Node 13.9.0 drop support for extensionless npm scripts ("bin") #488
Can you run node --version locally. There was never a Node.js version 3, as version three was part of the IO.js project. Currently supported versions of Node.js are 10, 12, 13.
Are you running code as CommonJS or ESM? If you are using ESM you need to include the full path to the resource you are trying to run.
There is nothing that we have done in Node.js to block npm scripts, which still are actively used across the ecosystem, and if I recall even internally in Node.js core for some of our tooling.
This is because --loader forces the ESM resolution algorithm not CJS resolution, and extension-less files are not resolved by default for ESM, see nodejs/node#31415
ghost changed the title [-]Node 13.9.0 blocks the use of npm scripts[/-][+]Node 13.9.0 blocks the use of npm scripts together with --loader funcionality[/+]on Feb 20, 2020
Overall, this is the intended behavior we got to after problems with having support for files lacking extensions in the ESM resolver; so I wouldn't think we need to fix this. My recommendation is you can have tsc map to a file with an extension, or expand the custom --loader supplied to support loading files without extensions (since it is overwriting how tsc works anyway).
Note it would still be an option for us to allow files without an extension for the Node.js CLI entry point only, as we had previously, which was specially implemented before for backwards compatibility cases like this.
@guybedford backwards compatibility breakage came from --loader, without --loader it still worked fine
ghost changed the title [-]Node 13.9.0 blocks the use of npm scripts together with --loader funcionality[/-][+]Node 3.9.0 drop support for extensionless files in CJS using in ESM[/+]on Feb 20, 2020
changed the title [-]Node 3.9.0 drop support for extensionless files in CJS using in ESM[/-][+]Node 13.9.0 drop support for extensionless files in CJS using in ESM[/+]on Feb 20, 2020
ghost changed the title [-]Node 13.9.0 drop support for extensionless files in CJS using in ESM[/-][+]Node 13.9.0 drop support for extensionless npm scripts ("bin")[/+]on Feb 21, 2020
Fixed some typos in sla100's loader fix and added the import:
importpathfrom'path';exportasyncfunctiongetFormat(urlString,context,defaultGetFormat){// support for extensionless files in "bin" scriptsif(/^file:\/\/\/.*\/bin\//.test(urlString)&&!path.extname(urlString)){return{format: 'module',};}returndefaultGetFormat(urlString,context,defaultGetFormat);}
To use this, node --experimental-loader loader.mjs ... though this does (currently) result in ugly warning messages.
Activity
MylesBorins commentedon Feb 20, 2020
Can you run
node --versionlocally. There was never a Node.js version 3, as version three was part of the IO.js project. Currently supported versions of Node.js are 10, 12, 13.Are you running code as CommonJS or ESM? If you are using ESM you need to include the full path to the resource you are trying to run.
There is nothing that we have done in Node.js to block npm scripts, which still are actively used across the ecosystem, and if I recall even internally in Node.js core for some of our tooling.
[-]Node 3.9.0 blocks the use of npm scripts[/-][+]Node 13.9.0 blocks the use of npm scripts[/+]bmeck commentedon Feb 20, 2020
This is because
--loaderforces the ESM resolution algorithm not CJS resolution, and extension-less files are not resolved by default for ESM, see nodejs/node#31415[-]Node 13.9.0 blocks the use of npm scripts[/-][+]Node 13.9.0 blocks the use of npm scripts together with --loader funcionality[/+]bmeck commentedon Feb 20, 2020
Overall, this is the intended behavior we got to after problems with having support for files lacking extensions in the ESM resolver; so I wouldn't think we need to fix this. My recommendation is you can have
tscmap to a file with an extension, or expand the custom--loadersupplied to support loading files without extensions (since it is overwriting howtscworks anyway).guybedford commentedon Feb 20, 2020
You should be able to work around this by implementing your custom loader to support a get_format hook which allows extensionless files.
Something like:
guybedford commentedon Feb 20, 2020
Note it would still be an option for us to allow files without an extension for the Node.js CLI entry point only, as we had previously, which was specially implemented before for backwards compatibility cases like this.
bmeck commentedon Feb 20, 2020
@guybedford backwards compatibility breakage came from --loader, without --loader it still worked fine
[-]Node 13.9.0 blocks the use of npm scripts together with --loader funcionality[/-][+]Node 3.9.0 drop support for extensionless files in CJS using in ESM[/+][-]Node 3.9.0 drop support for extensionless files in CJS using in ESM[/-][+]Node 13.9.0 drop support for extensionless files in CJS using in ESM[/+][-]Node 13.9.0 drop support for extensionless files in CJS using in ESM[/-][+]Node 13.9.0 drop support for extensionless npm scripts ("bin")[/+]tadman commentedon Mar 23, 2021
Fixed some typos in sla100's loader fix and added the
import:To use this,
node --experimental-loader loader.mjs ...though this does (currently) result in ugly warning messages.Is there a more transparent way to include this?
unicornware commentedon Oct 1, 2021
@tadman it silences all warnings, but i've been using
NODE_NO_WARNINGS=1build: use esm
build: use esm
build: use esm
build: use esm
build!: use esm
build!: use esm