getnote-cli icon indicating copy to clipboard operation
getnote-cli copied to clipboard

WSL: launcher resolves extension-less "getnote", but a Windows npm install ships only getnote.exe (spawn ENOENT)

Open RayOdyssey opened this issue 1 month ago • 1 comments

Summary

When @getnote/cli is installed with Windows npm but invoked from WSL, every command fails with an unhandled spawn ... ENOENT. The JavaScript launcher picks the binary name from the runtime OS (linux), while the Windows install placed only getnote.exe in bin/.

Observed on 1.5.7. main at 6bc4218 (v1.8.2) still has the same launcher (blob d437ce0a).

Environment

  • WSL2 2.7.10.0, kernel 6.18.33.2-microsoft-standard-WSL2
  • Node.js v18.19.1 inside WSL (os.platform() returns linux)
  • Installed by Windows npm (npm i -g @getnote/cli; Node.js v24.18.1)
  • The npm prefix is on a Windows drive mounted in WSL (/mnt/<drive>/<npm-prefix>, DrvFs)
  • Installed layout: bin/getnote.js and bin/getnote.exe; no bin/getnote

Reproduction

node /mnt/<drive>/<npm-prefix>/node_modules/@getnote/cli/bin/getnote.js --version

Actual:

Error: spawn .../node_modules/@getnote/cli/bin/getnote ENOENT
  code: 'ENOENT',
  syscall: 'spawn .../bin/getnote'

Control: the same getnote.exe --version prints getnote version v1.5.7 (exit 0). The binary is fine; only the name lookup is wrong.

Expected: it runs, or fails with a clear message naming the missing binary.

Root cause

bin/getnote.js:

  • line 10: os.platform() returns linux under WSL
  • line 11: platform === 'win32' ? 'getnote.exe' : 'getnote' selects getnote
  • line 12: resolves bin/getnote, which does not exist
  • line 14: spawn(...) has no error listener

scripts/postinstall.js installs only the platform-matching binary into bin/. Since v1.5.10 the package also ships all six binaries under prebuilt/, but the launcher never looks there.

Suggested fix

Change line 12 to let binaryPath = ..., add const fs = require('fs'), then (the error handler is required either way):

if (!fs.existsSync(binaryPath)) {
  const p = { win32: 'windows', darwin: 'darwin', linux: 'linux' }[platform];
  const a = { x64: 'amd64', arm64: 'arm64' }[os.arch()];
  const native = path.join(__dirname, '..', 'prebuilt', `${p}-${a}`, binaryName);
  const other = path.join(__dirname, binaryName === 'getnote.exe' ? 'getnote' : 'getnote.exe');
  if (fs.existsSync(native)) binaryPath = native;
  else if (fs.existsSync(other)) binaryPath = other;
}
if (!fs.existsSync(binaryPath)) {
  console.error(`getnote: no binary for ${platform}/${os.arch()} at ${binaryPath}`);
  process.exit(1);
}
child.on('error', (err) => {
  console.error(`getnote: failed to start ${binaryPath}: ${err.message}`);
  process.exit(1);
});

The prebuilt/ lookup lets v1.5.10+ run the native Linux build; the other-name lookup covers older packages and the mirror case.

Impact

Cross-OS mounts only: Linux Node.js invoking a Windows-installed package (WSL), or the reverse. Native installs are unaffected.

Workaround

Call bin/getnote.exe directly, for example via a wrapper on PATH:

exec "/mnt/<drive>/<npm-prefix>/node_modules/@getnote/cli/bin/getnote.exe" "$@"

I can prepare a PR if this direction looks right.

RayOdyssey avatar Oct 24 '26 01:10 RayOdyssey

感谢如此详细的 bug 报告和修复建议!

确认

你的分析完全正确:

  • ✅ 问题根因定位准确(os.platform() 在 WSL 返回 linux,但 Windows npm 只安装了 .exe)
  • ✅ 修复方案合理(fallback 到 prebuilt/ 或反向查找另一个扩展名)
  • ✅ 影响范围清晰(仅跨 OS 挂载场景)

决定

欢迎 PR!

建议修复方向:

  1. 优先级:

    • 先尝试 bin/getnote.exe / bin/getnote(当前逻辑)
    • 然后尝试另一个扩展名(.exe ↔ 无扩展名)
    • 最后尝试 prebuilt/<platform-arch>/
  2. 错误处理:

    • 在所有路径都不存在时,输出清晰的错误信息
    • 为 spawn 添加 error 事件监听器
  3. 测试:

    • 如果方便,请在 WSL 环境验证修复后的行为
    • 确保不影响正常的原生安装场景

下一步

请提交 PR,我会尽快 review 和合并。可以参考你提供的代码框架,如果需要调整会在 PR 中讨论。

再次感谢详细的问题报告和解决方案!这对 WSL 用户会很有帮助。

iswalle avatar Nov 04 '26 06:11 iswalle