Windows 前端开发问题汇总

927 阅读1分钟

To Be Continued...

stdout is not a tty

git bash 中 node.js 程序用管道交互会出现该问题。解决方案:增加 #!/bin/env node。详见在Node.js中使用stdout、stdin和stderr的方法

Windows node.js ERR_UNSUPPORTED_ESM_URL_SCHEME #Node.js

Windows Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'f:' at new NodeError (node:internal/errors:387:5)

该问题常出现在运行时加载文件,是 Windows 独有 bug。

解决

需要将磁盘格式(即 path) 'f:/path/to/file.js' 转成 import 或 require 支持的 scheme (即 filepath) 'file:///f:/path/to/file.js' in node.js。

需要用到 pathToFileURL

const filepath = pathToFileURL(path.join(process.cwd(), input)).href;

感想

没想到node.js也有兼容性问题 -_-||

ssh-key command not found

ssh-keygen -t ed25519 -C "example@qq.com"

bash: ssh-keygen: command not found

一般来说安装 git for Windows 后自带该命令吗,如果没有找到可以试试 /usr/bin/ssh-keygen.exe