部署到heroku [错误:生成babel-node ENOENT]

时间:2018-05-01 12:35:04

标签: node.js heroku compiler-errors nextjs

项目在开发机上完美运行。我已经花了5个多小时:

  • 使用远程heroku上的bash'start'脚本尝试不同的配置

  • 将babel-cli和babel-preset-env安装为依赖项而不是devDependencies

  • 阅读有关本地版本的heroku文档,试用 它们

  • 禁用生产中的dotenv

您对这个babel节点和heroku不兼容有什么建议/解决方案?也许他们正在禁用它,因为它会对服务器内存产生更大的负担?我已经在ES6中编写了所有文件,并尝试将它们重写为旧语法,但这几乎是不可能的。有没有办法让babel在服务器端为heroku工作?

Heroku应用程序日志:

2018-05-01T12:08:44.677261+00:00 heroku[web.1]: Starting process with command `npm start`
2018-05-01T12:08:47.873964+00:00 app[web.1]: [heroku-exec] Starting
2018-05-01T12:08:48.920661+00:00 app[web.1]: 
2018-05-01T12:08:48.920707+00:00 app[web.1]: > rearn@1.0.0 start /app
2018-05-01T12:08:48.920710+00:00 app[web.1]: > cross-env NODE_ENV=production babel-node server/server.js
2018-05-01T12:08:48.920712+00:00 app[web.1]: 
2018-05-01T12:08:49.196690+00:00 app[web.1]: events.js:183
2018-05-01T12:08:49.196703+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2018-05-01T12:08:49.196704+00:00 app[web.1]:       ^
2018-05-01T12:08:49.196706+00:00 app[web.1]: 
2018-05-01T12:08:49.196709+00:00 app[web.1]: Error: spawn babel-node ENOENT
2018-05-01T12:08:49.196710+00:00 app[web.1]:     at _errnoException (util.js:1024:11)
2018-05-01T12:08:49.196712+00:00 app[web.1]:     at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
2018-05-01T12:08:49.196714+00:00 app[web.1]:     at onErrorNT (internal/child_process.js:372:16)
2018-05-01T12:08:49.196717+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:138:11)
2018-05-01T12:08:49.196718+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:180:9)
2018-05-01T12:08:49.196720+00:00 app[web.1]:     at Function.Module.runMain (module.js:678:11)
2018-05-01T12:08:49.196721+00:00 app[web.1]:     at startup (bootstrap_node.js:187:16)
2018-05-01T12:08:49.196723+00:00 app[web.1]:     at bootstrap_node.js:608:3
2018-05-01T12:08:49.206967+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-05-01T12:08:49.208660+00:00 app[web.1]: npm ERR! errno 1
2018-05-01T12:08:49.211774+00:00 app[web.1]: npm ERR! rearn@1.0.0 start: `cross-env NODE_ENV=production babel-node server/server.js`
2018-05-01T12:08:49.212391+00:00 app[web.1]: npm ERR! Exit status 1
2018-05-01T12:08:49.212731+00:00 app[web.1]: npm ERR! 
2018-05-01T12:08:49.212944+00:00 app[web.1]: npm ERR! Failed at the rearn@1.0.0 start script.
2018-05-01T12:08:49.213151+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-05-01T12:08:49.220087+00:00 app[web.1]: 
2018-05-01T12:08:49.220400+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-05-01T12:08:49.220579+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-05-01T12_08_49_214Z-debug.log
2018-05-01T12:08:49.315806+00:00 heroku[web.1]: State changed from starting to crashed
2018-05-01T12:08:49.301459+00:00 heroku[web.1]: Process exited with status 1

的package.json:

{
  "name": "rearn",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "engines": {
    "node": "8.9.3",
    "npm": "5.6.0"
  },
  "scripts": {
    "build": "next build",
    "start": "cross-env NODE_ENV=production babel-node server/server.js",
    "test": "eslint pages components lib",
    "dev": "nodemon server/server.js --watch server --exec babel-node server/server.js",
    "port": "cross-env PORT=4000 npm start",
    "prod": "yarn build && cross-env NODE_ENV=production babel-node server/server.js",
    "precommit": "yarn test",
    "prepush": "yarn test",
    "heroku-postbuild": "YARN_PRODUCTION=false yarn install && yarn build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@zeit/next-sass": "^0.1.2",
    "axios": "^0.18.0",
    "bootstrap": "4.0.0",
    "bootstrap-material-design": "^4.1.1",
    "connect-mongo": "^2.0.1",
    "cross-env": "^5.1.4",
    "dotenv": "^5.0.1",
    "express": "^4.16.3",
    "express-session": "^1.15.6",
    "express-useragent": "^1.0.12",
    "jquery": "^3.3.1",
    "material-ui": "^0.20.0",
    "mongoose": "^5.0.15",
    "next": "5.1.0",
    "next-offline": "^2.5.0",
    "next-redux-wrapper": "^1.3.5",
    "node-sass": "^4.8.3",
    "passport": "^0.4.0",
    "passport-google-oauth": "^1.0.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-popper": "^0.10.1",
    "react-redux": "^5.0.7",
    "react-reveal": "^1.2.1",
    "react-transition-group": "^2.3.0",
    "redux": "^4.0.0",
    "redux-form": "^7.3.0",
    "redux-thunk": "^2.2.0",
    "styled-jsx": "^2.2.6",
    "workbox-background-sync": "^3.0.1"
  },
  "browserslist": [
    "> 1%"
  ],
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "eslint": "4.9.0",
    "eslint-config-airbnb": "16.1.0",
    "eslint-plugin-compat": "^2.2.0",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-jsx-a11y": "6.0.2",
    "eslint-plugin-react": "7.4.0",
    "husky": "^0.14.3"
  }
}

2 个答案:

答案 0 :(得分:1)

解决。实际上我是在bash中删除并安装babel-cli和babel-preset-env,并且某种程度上heroku没有远程更新package.json?为什么?解决方案:

  • 安装babel-cli和babel-preset-env作为依赖项而不是 devDependencies(实际上babel-cli只适用于next.js,因为它使用最新的babel配置)。

答案 1 :(得分:1)

找到了这篇文章,因为我有类似的问题。 移动了整个

"@babel/cli": "7.5.5",
"@babel/core": "7.5.5",
"@babel/node": "7.5.5",
"@babel/plugin-transform-runtime": "7.5.5",
"@babel/preset-env": "7.5.5",
"@babel/runtime": "7.5.5",

从devDepenencies到package.json =依赖项部分,目前已解决问题,也许不是最终的完美解决方案,难解决