2017-07-18 165 views
4

在服務器上「npm run build」時出現以下錯誤。在本地計算機上工作正常。獲取有關服務器
節點版本500響應:8.0
NPM版本:5.0.3找不到模塊'has-flag'

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. 
+0

你能分享一些環境細節嗎? – WhatsThePoint

+1

你可以運行'npm ls'併發布結果嗎? – brennanenanen

+0

有誰知道是什麼改變,使這個必要?我只是同時更新了一堆東西(包括節點7-> 8,npm 3-> 5和幾個節點),並且不知道這個附加依賴來自哪裏...... – Lucas

回答

3

嘗試npm install --save has-flag。它看起來像supports-color需要安裝has-flag,但它不是。如果您需要安裝任何其他軟件包,您只需鍵入npm install

+1

沒有必要使用'-g' – robertklep

+0

好點。我輸入了錯誤的東西。哎呦。 – brennanenanen

+1

使用上述命令我得到了最新版本的has-flag,所以我使用了「npm install [email protected]」作爲特定版本 –