2017-07-17 66 views
0

我在Heroku上使用ES6語法的babel-node,但在部署時出現構建錯誤。它說「babel-node:not found」。我已經嘗試在本地計算機上進行全新安裝,並且完美地工作。 Package.json:Heroku上沒有安裝babel-node

{ 
    "name": "secret", 
    "version": "0.0.0", 
    "private": true, 
    "scripts": { 
    "start": "./node_modules/.bin/babel-node ./bin/www" 
    }, 
    "engines": { 
    "node": "7.5.0", 
    "npm": "5.0.3" 
    }, 
    "dependencies": { 
    "babel-cli": "^6.24.1", 
    "babel-preset-es2015": "^6.24.1", 
    "babel-preset-stage-0": "^6.24.1", 
    ... 
    } 
} 

我感謝您的幫助! :)

2017-07-17T11:02:26.997876+00:00 heroku[web.1]: State changed from crashed to starting 
2017-07-17T11:02:31.839278+00:00 heroku[web.1]: Starting process with command `npm start` 
2017-07-17T11:02:38.074157+00:00 heroku[web.1]: State changed from starting to crashed 
2017-07-17T11:02:38.062607+00:00 heroku[web.1]: Process exited with status 1 
2017-07-17T11:02:37.865774+00:00 app[web.1]: 
2017-07-17T11:02:37.865786+00:00 app[web.1]: > [email protected] start /app 
2017-07-17T11:02:37.865787+00:00 app[web.1]: > babel-node ./bin/www 
2017-07-17T11:02:37.865787+00:00 app[web.1]: 
2017-07-17T11:02:37.936361+00:00 app[web.1]: sh: 1: babel-node: not found 
2017-07-17T11:02:37.966452+00:00 app[web.1]: npm ERR! file sh 
2017-07-17T11:02:37.966683+00:00 app[web.1]: npm ERR! code ELIFECYCLE 
2017-07-17T11:02:37.966931+00:00 app[web.1]: npm ERR! errno ENOENT 
2017-07-17T11:02:37.967106+00:00 app[web.1]: npm ERR! syscall spawn 
2017-07-17T11:02:37.967287+00:00 app[web.1]: npm ERR! [email protected] start: `babel-node ./bin/www` 
2017-07-17T11:02:37.967430+00:00 app[web.1]: npm ERR! spawn ENOENT 
2017-07-17T11:02:37.967588+00:00 app[web.1]: npm ERR! 
2017-07-17T11:02:37.967733+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script. 
2017-07-17T11:02:37.967873+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 
2017-07-17T11:02:37.969151+00:00 app[web.1]: 
2017-07-17T11:02:37.969374+00:00 app[web.1]: npm ERR! A complete log of this run can be found in: 
2017-07-17T11:02:37.969484+00:00 app[web.1]: npm ERR!  /app/.npm/_logs/2017-07-17T11_02_37_957Z-debug.log 
2017-07-17T11:25:52.044791+00:00 heroku[web.1]: State changed from crashed to starting 
2017-07-17T11:25:54.841341+00:00 heroku[web.1]: Starting process with command `npm start` 
2017-07-17T11:25:57.407691+00:00 heroku[web.1]: Process exited with status 1 
2017-07-17T11:25:57.413873+00:00 heroku[web.1]: State changed from starting to crashed 
2017-07-17T11:25:57.310176+00:00 app[web.1]: 
2017-07-17T11:25:57.310190+00:00 app[web.1]: > [email protected] start /app 
2017-07-17T11:25:57.310191+00:00 app[web.1]: > babel-node ./bin/www 
2017-07-17T11:25:57.310192+00:00 app[web.1]: 
2017-07-17T11:25:57.316940+00:00 app[web.1]: sh: 1: babel-node: not found 
2017-07-17T11:25:57.335019+00:00 app[web.1]: npm ERR! file sh 
2017-07-17T11:25:57.335287+00:00 app[web.1]: npm ERR! code ELIFECYCLE 
2017-07-17T11:25:57.335517+00:00 app[web.1]: npm ERR! errno ENOENT 
2017-07-17T11:25:57.335735+00:00 app[web.1]: npm ERR! syscall spawn 
2017-07-17T11:25:57.335933+00:00 app[web.1]: npm ERR! [email protected] start: `babel-node ./bin/www` 
2017-07-17T11:25:57.336095+00:00 app[web.1]: npm ERR! spawn ENOENT 
2017-07-17T11:25:57.336280+00:00 app[web.1]: npm ERR! 
2017-07-17T11:25:57.336449+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script. 
2017-07-17T11:25:57.336614+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 
2017-07-17T11:25:57.337985+00:00 app[web.1]: 
2017-07-17T11:25:57.338232+00:00 app[web.1]: npm ERR! A complete log of this run can be found in: 
2017-07-17T11:25:57.338379+00:00 app[web.1]: npm ERR!  /app/.npm/_logs/2017-07-17T11_25_57_323Z-debug.log 
+0

鍵入'npm list -g babel-node'會給你什麼? – brennanenanen

+0

它給 - (空)。 babel-cli-package在node_modules /中,但可執行文件不在node_modules/.bin中 – justasking

+0

嗯,我不知道。我假設你已經試過'npm我-g babel-node' – brennanenanen

回答

0

有點晚,但這裏是什麼,我認爲你缺少:

步驟(1):npm install --save babel-cli babel-preset-env在終端

注意事項第1步:不要保存到dev因爲這將需要你設置NPM_CONFIG_PRODUCTION = false

步驟(2):你沒有編譯任何東西給babel而沒有添加babel樣板文件或使用babelrc文件。最簡單的方法是在主應用程序文件夾中創建一個.babelrc文件,即。同一個你的package.json中輸入以下內容:在第2步

{ 
    "presets": ["env"] 
} 

注:隨着ENV的使用預置您不需要巴貝爾預設-ES2015等

步驟( 3):你現在可以使用babel-node運行你的代碼,所以在你的情況下執行你的啓動腳本,即。 ./node_modules/.bin/babel-node ./bin/www

我建議通過NPM模塊閱讀,如果您需要進一步的指導瞭解預設的邏輯:https://www.npmjs.com/package/babel-preset-env

此外,我會使用像PM2的過程經理建議。這允許您的節點實例在崩潰時保持活動狀態。用來做這件事的永遠模塊,但是pm2更好。以下是您的package.json中的一個啓動腳本示例:

「scripts」:{ 「start」:「node ./node_modules/.bin/pm2 start main.json --attach --env production」 }

Procfile(注意,我使用nginx的,但只是故宮開始就正常工作):

web: bin/start-nginx npm start 
worker: node ./node_modules/.bin/pm2 start worker.json --attach 

這裏將是你的main.json與args設置爲使用通天節點(注意,保持實例到1,不要在Heroku上的網絡測試儀上分叉):

main.json:

{ 
    "name": "the_awesome", 
    "script": "app.js", 
    "instances": 1, 
    "exec_mode": "cluster" 
} 

worker.json:

{ 
    "name": "worker", 
    "script": "/app/lib/worker.js" 
} 

(4)添加一個需要( '巴別塔註冊')鉤到您的app.js和worker.js如果您正在使用pm2在集羣模式下。如果您使用pm2而不是集羣模式,或者只是不使用pm2,那麼您可以直接使用babel-node來運行.js或es6文件。

最後,要檢查是否真的安裝了babel節點,您可以執行如下:

heroku run bash -a {name of your app} 
ls ./node_modules/.bin //babel-node should be present 

祝你好運!