Heroku: Error: Cannot find module node-gyp

Heroku: Error: Cannot find module node-gyp

昨天(2018 年 3 月 23 日)在 heroku 部署中开始出现此错误,不知道为什么。没有包更改或与节点模块相关的任何内容。此错误在 yarn install

上引发

如有任何帮助,我们将不胜感激。

    [4/4] Building fresh packages...
    error An unexpected error occurred: "/tmp/build_0ee997c3e293524b58e17ee6d643ada3/blog/node_modules/sharp: Command failed.
    Exit code: 1
    Command: sh
    Arguments: -c node-gyp rebuild
    Directory: /tmp/build_0ee997c3e293524b58e17ee6d643ada3/blog/node_modules/sharp
    Output:
    module.js:545
      throw err;
      ^
    Error: Cannot find module '/tmp/build_0ee997c3e293524b58e17ee6d643ada3/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js'
      at Function.Module._resolveFilename (module.js:543:15)
      at Function.Module._load (module.js:470:25)
      at Function.Module.runMain (module.js:690:10)
      at startup (bootstrap_node.js:194:16)
      at bootstrap_node.js:666:3".
         info If you think this is a bug, please open a bug report with the information provided in "/tmp/build_0ee997c3e293524b58e17ee6d643ada3/blog/yarn-error.log".
         info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
    error An unexpected error occurred: "Command failed.
    Exit code: 1
    Command: sh
    Arguments: -c cd blog && yarn install && yarn deploy && cd ..
    Directory: /tmp/build_0ee997c3e293524b58e17ee6d643ada3
    Output:
    ".
         info If you think this is a bug, please open a bug report with the information provided in "/tmp/build_0ee997c3e293524b58e17ee6d643ada3/yarn-error.log".
         info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    error An unexpected error occurred: "Command failed.
    Exit code: 1
    Command: sh

问题是由于 NPM 发布了一个损坏的更新。从 5.8.0 回滚到 5.7.1

--编辑-- 要在 Heroku 上锁定 NPM 版本,请将以下代码添加到您的 package.json 文件中。 "engines": { "npm": "5.7.1" ...other stuff },