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

fix: fix commands broken on early versions of Node.js v18, v20 and v21 #1503

Merged
merged 1 commit into from
Feb 14, 2025

Conversation

xnv
Copy link
Member

@xnv xnv commented Feb 13, 2025

掲題どおり。

ESM になっているモジュールにおいて、bin/run のように拡張子のないファイルは、ある時期までの Node.js で (デフォルトでは) サポートされていない ようです 。具体的には v18.19.0 未満の v18 系や、v20.10.0 未満の v20 系が該当する とのこと

$ ./node_modules/.bin/akashic-cli-sandbox 
node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^    

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /(...snip...)/node_modules/@akashic/akashic-cli-sandbox/bin/akashic-cli-sandbox. Loading extensionless files is not supported inside of "type":"module" package.json contexts. The package.json file /(...snip...)/node_modules/@akashic/akashic-cli-sandbox/package.json caused this "type":"module" context. Try changing /(...snip...)/node_modules/@akashic/akashic-cli-sandbox/bin/akashic-cli-sandbox to have a file extension. Note the "bin" field of package.json can point to a file with an extension, for example {"type":"module","bin":{"akashic-cli-sandbox":"./bin/akashic-cli-sandbox.js"}}
    at new NodeError (node:internal/errors:399:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:121:38)
    at defaultLoad (node:internal/modules/esm/load:81:20)
    at nextLoad (node:internal/modules/esm/loader:163:28)
    at ESMLoader.load (node:internal/modules/esm/loader:605:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
    at new ModuleJob (node:internal/modules/esm/module_job:64:26)
    at #createModuleJob (node:internal/modules/esm/loader:480:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

EOL が近い v18 はまだしも v20 でトラブルになるのは避けたく、エラーメッセージのとおり拡張子を追加します。

package.json の bin 指定の問題なので、ユニットテストや test/e2e.js の --local では動作確認できません。Mac 上の Node 18.16.0 で sandbox, export などいくつか npm pack する限りでは問題ないので、prerelease で publish したもので動作確認します。

@@ -6,7 +6,7 @@
"main": "index.js",
"scripts": {
"prepublish": "npm run build",
"start": "npm run build && node bin/run",
"start": "npm run build && node bin/akashic-cli-sandbox.js",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別件: 元々パスがおかしかったようなので修正。(sandbox で npm start することはなさそうなので、削除してしまっても良さそうですが)

},
"scripts": {
"prepublish": "npm run clean && npm run build",
"clean": "rimraf ./lib && rimraf ./spec/build",
"start": "npm run build && node bin/run",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別件2: 元々なかったファイルを指していました。extra 自体に start はありえないので削除。

@xnv xnv merged commit 662a0b0 into main Feb 14, 2025
9 checks passed
@xnv xnv deleted the fix-bin-ext branch February 14, 2025 07:02
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

Successfully merging this pull request may close these issues.

3 participants