npm安装仅在与child_process.exec一起使用时失败



在我的终端中运行此程序:npm i --save-dev typescript 'https://gitpkg.now.sh/pylonbot/pylon-sdk-types/runtime' 'https://gitpkg.now.sh/pylonbot/pylon-sdk-types/runtime-discord'
按照预期安装程序包。但是,当我尝试使用child_process的execSync来安装这些包时,安装失败了。代码:

try {
child_process.execSync(`npm i --save-dev typescript 'https://gitpkg.now.sh/pylonbot/pylon-sdk-types/runtime' 'https://gitpkg.now.sh/pylonbot/pylon-sdk-types/runtime-discord'`);
} catch(e) {
console.log(e);
process.exit();
} finally {
console.log('It worked!');
}

输出:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:Usersmetest'https:gitpkg.now.shpylonbotpylon-sdk-typesruntime'/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:Usersmetest'https:gitpkg.now.shpylonbotpylon-sdk-typesruntime'package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

有趣的是,它只有在包含gitpkgs时才会失败(gitpkg是一个可以让您从github子目录安装软件包的工具(
如果这是愚蠢的事情,请提前道歉,但我无法理解。

无论出于何种原因,删除gitpkg链接周围的引号都解决了这个问题。

最新更新