Consider something clever for extension-less executables #32316
Closed
Description
It would be nice if ECMAScript shebang files with no extension
a. worked :)
b. were assumed to be modules for Node.js current+
Especially for server people that have lots of command-line scripts
And I think we should plan for a future without require
exhibit:
node --print '"#!/usr/bin/env node\n// node --experimental-modules e\nimport {inspect} from QutilQ\nconsole.log(`${inspect(QabcQ)}`)".replace(/Q/g, String.fromCharCode(39))' >e && chmod +x e ./e (node:38910) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. /opt/foxyboy/sw/pri/subtree/ecmascript2049/packages/e:3 import {inspect} from 'util' ^^^^^^ SyntaxError: Cannot use import statement outside a module at wrapSafe (internal/modules/cjs/loader.js:1063:16) at Module._compile (internal/modules/cjs/loader.js:1111:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10) at Module.load (internal/modules/cjs/loader.js:996:32) at Function.Module._load (internal/modules/cjs/loader.js:896:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47 $ cat e #!/usr/bin/env node // node --experimental-modules e import {inspect} from 'util' console.log(`${inspect('abc')}`)
This shebang no work either:
#!/usr/local/bin/node --experimental-modules
The solutions at present is to:
- use .mjs extension
- symlink to a file that has .mjs extension. Not portable, I suppose, on certain file systems from up north and Applish implementations of WebDAV
- have a package.json in the same or superior directory. May cause unforeseen troubles
- symlink to a directory with a package.json. Possibly not portable
node -v && uname -a
v13.11.0
Darwin c87m1.local 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64
A related trouble is if you happen to have a native-code dependency. requires node_modules and such
Activity