【问题标题】:Cannot find module 'has-flag'找不到模块“有标志”
【发布时间】:2017-07-18 08:44:24
【问题描述】:

在服务器上“npm run build”时出现以下错误。在本地机器上工作正常。在服务器上获得 500 响应
节点版本:8.0
npm 版本:5.0.3

    Error: Cannot find module 'has-flag'  
    at Function.Module._resolveFilename (module.js:485:15)  
    at Function.Module._load (module.js:437:25)  
    at Module.require (module.js:513:17)  
    at require (internal/module.js:11:18)  
    at Object.<anonymous>  
 (/usr/share/../../../node_modules/postcss/node_modules/supports-color/index.js:2:15)  
    at Module._compile (module.js:569:30)  
    at Object.Module._extensions..js (module.js:580:10)  
    at Module.load (module.js:503:32)  
    at tryModuleLoad (module.js:466:12)  
    at Function.Module._load (module.js:458:3)  
npm ERR! code ELIFECYCLE  
npm ERR! errno 1  
npm ERR! ***@0.1.0 build: `react-scripts build`  
npm ERR! Exit status 1  
npm ERR!   
npm ERR! Failed at the ***@0.1.0 build script.  
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

【问题讨论】:

  • 可以分享一些环境细节吗?
  • 你能运行npm ls 并发布结果吗?
  • 有谁知道发生了什么变化使得这变得必要?我只是同时更新了一堆东西(包括node 7->8,npm 3->5,还有几个deps),不知道这个额外的依赖是从哪里来的……

标签: node.js reactjs npm


【解决方案1】:

试试npm install --save has-flag。看起来supports-color 需要安装has-flag,但事实并非如此。如果您需要安装任何其他软件包,您只需输入npm install

【讨论】:

  • 不用-g
  • 使用上面的命令我得到了最新版本的has-flag,所以我使用“npm install has-flag@1.0.0”作为特定版本
【解决方案2】:

以上方法对我不起作用,但删除我的 node_modules 和 dist 文件夹并重新运行 npm install 可以。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-29
    • 2022-12-15
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 2018-02-21
    • 2018-12-09
    • 2021-07-23
    相关资源
    最近更新 更多