2016-09-12 100 views
5

對Node非常新,並部署到Heroku。我有一個基本的React應用程序設置,並試圖部署到Heroku。我推它,但應用程序失敗。當我看到日誌時,我看到一些有關sh: 1: webpack: not found(完整日誌here未找到Webpack,部署到Heroku

我不是很確定發生了什麼,但相信它與我的package.json有關?從我用起始模板是這樣的:

{ 
    "name": "express-react-redux-starter", 
    "version": "1.0.0", 
    "description": "Starter for Express, React, Redux, SCSS applications", 
    "scripts": { 
     "dev": "webpack-dev-server --config ./webpack/webpack-dev.config.js --watch --colors", 
     "build": "rm -rf dist && webpack --config ./webpack/webpack-prod.config.js --colors", 
     "start": "PORT=8080 node start ./server.js", 
     "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test", 
     "test:watch": "npm run test -- --watch", 
     "lint": "eslint src test webpack" 
    }, 
    "keywords": [ 
     "ExpressJS", 
     "ReactJS", 
     "Redux", 
     "React hot loader", 
     "React Router", 
     "SCSS", 
     "Webpack Devevelopment configuration", 
     "Webpack Production configuration", 
     "Airbnb Eslint", 
     "pm2", 
     "mocha", 
     "chai" 
    ], 
    "repository": { 
     "type": "git", 
     "url": "git+https://github.com/DimitriMikadze/express-react-redux-starter" 
    }, 
    "author": "Dimitri Mikadze", 
    "license": "MIT", 
    "devDependencies": { 
     "autoprefixer": "^6.4.0", 
     "autoprefixer-loader": "^3.2.0", 
     "babel-core": "^6.8.0", 
     "babel-loader": "^6.2.4", 
     "babel-preset-es2015": "^6.6.0", 
     "babel-preset-react": "^6.5.0", 
     "babel-preset-stage-1": "^6.5.0", 
     "chai": "^3.5.0", 
     "chai-jquery": "^2.0.0", 
     "css-loader": "^0.23.1", 
     "eslint": "^2.10.2", 
     "eslint-config-airbnb": "^9.0.1", 
     "eslint-plugin-import": "^1.8.0", 
     "eslint-plugin-jsx-a11y": "^1.2.0", 
     "eslint-plugin-react": "^5.1.1", 
     "extract-text-webpack-plugin": "^1.0.1", 
     "html-webpack-plugin": "^2.16.1", 
     "jquery": "^2.2.3", 
     "jsdom": "^9.0.0", 
     "mocha": "^2.4.5", 
     "node-sass": "^3.7.0", 
     "react-addons-test-utils": "^15.0.2", 
     "react-hot-loader": "^1.3.0", 
     "sass-loader": "^3.2.0", 
     "style-loader": "^0.13.1", 
     "url-loader": "^0.5.7", 
     "webpack-dev-server": "^1.14.1" 
    }, 
    "dependencies": { 
     "classnames": "^2.2.5", 
     "express": "^4.13.4", 
     "lodash": "^4.15.0", 
     "react": "^15.0.2", 
     "react-dom": "^15.0.2", 
     "react-redux": "^4.4.5", 
     "react-router": "^2.4.0", 
     "redux": "^3.5.2", 
     "webpack": "^1.13.0" 
    } 
} 

我該怎麼做不正確地得到這種部署?在我的本地主機上運行良好。但無法弄清楚如何在我的生活中將它融入世界。非常感謝!

回答

16

好的 - 這與devDependencies和package.json中的依賴關係有關 另外,通過將Heroku配置設置爲NPM_CONFIG_PRODUCTION: false我能夠解決這個問題。 Thx互聯網!

+0

NPM_CONFIG_PRODUCTION:假的,爲什麼你會怎麼做這個?默認情況下,heroku會安裝依賴關係,而不是devDependencies。另外webpack dev服務器不適用於生產。 – mdcuesta

+0

謝謝,解決我的問題 –

+0

heroku config:set NPM_CONFIG_PRODUCTION = false是這個建議的語法。 –

4

這是因爲Heroku的默認不安裝的package.json的dev的相關性,我們需要exculsively告訴的Heroku(NPM)來安裝我們的開發依賴(的WebPack是在開發中),因此運行這個命令就可以解決這個 「找不到問題」

npm install --dev 
+1

這是一個更好的解決方案。 – ivarni

+1

我在heroku-preinstall腳本中使用--only = dev。這似乎是新的/正確的方式。非常感謝!!! – SomethingOn

1

下面的命令,應該可以解決您的問題heroku config:set NPM_CONFIG_PRODUCTION=false

這有助於Heroku的從 「devDependencies」 目錄中安裝packajes(非氟里昂 「依賴」)