【问题标题】:npm install only fails when used with child_process.execnpm install 仅在与 child_process.exec 一起使用时才会失败
【发布时间】:2022-02-06 04:24:26
【问题描述】:

在我的终端中运行它: 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:\Users\me\test\'https:\gitpkg.now.sh\pylonbot\pylon-sdk-types\runtime'/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\me\test\'https:\gitpkg.now.sh\pylonbot\pylon-sdk-types\runtime'\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

有趣的是,它仅在包含 gitpkgs 时才会失败(gitpkg 是一个允许您从 github 子目录安装软件包的工具)
如果这是愚蠢的事情,请提前抱歉,但我无法弄清楚。

【问题讨论】:

    标签: node.js npm child-process


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-04-16
      • 1970-01-01
      • 2016-01-22
      • 1970-01-01
      • 2017-01-17
      • 2019-02-23
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多