首页 > 解决方案 > 在 heroku 上部署 Nodejs 应用程序时出现 BABEL_PARSE_ERROR

问题描述

我正在 Heroku 服务器上部署节点 js 应用程序。我正在将 webpack 用于 es6 语法,并且它在我本地的所有内容都可以正常工作。

但是当我尝试在 heroku 上部署代码时,它会给出 BABEL_PARSE_ERROR。

remote:        > taleem-backend@1.0.0 build /tmp/build_dbe1f098c9b56734350ccb6e4f4c0166
remote:        > rimraf dist/ && babel ./ --out-dir dist
remote:        
remote: SyntaxError: /tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/.heroku/node/lib/node_modules/npm/docs/gatsby-browser.js: Unexpected token (7:9)
remote: 
remote:   5 | 
remote:   6 | export const wrapPageElement = ({ element, props }) => {
remote: > 7 |   return <Layout {...props} >{element}</Layout>
remote:     |          ^
remote:   8 | }
remote:   9 | 
remote:     at Parser.raise (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:7017:17)
remote:     at Parser.unexpected (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:8395:16)
remote:     at Parser.parseExprAtom (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:9673:20)
remote:     at Parser.parseExprSubscripts (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:9259:23)
remote:     at Parser.parseMaybeUnary (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:9239:21)
remote:     at Parser.parseExprOps (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:9109:23)
remote:     at Parser.parseMaybeConditional (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:9082:23)
remote:     at Parser.parseMaybeAssign (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:9037:21)
remote:     at Parser.parseExpression (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:8989:23)
remote:     at Parser.parseReturnStatement (/tmp/build_dbe1f098c9b56734350ccb6e4f4c0166/node_modules/@babel/parser/lib/index.js:11057:28) {
remote:   pos: 209,
remote:   loc: Position { line: 7, column: 9 },
remote:   code: 'BABEL_PARSE_ERROR'
remote: }
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! taleem-backend@1.0.0 build: `rimraf dist/ && babel ./ --out-dir dist`
remote: npm ERR! Exit status 1

上面的错误出现在 node_modules 中,但我已经在 webpack.config.js 中忽略了我的 node_modules,并且我在我的本地仔细检查了它的工作正常(忽略逻辑)

heroku local web

我运行上面的命令,正如它在 heroku 文档中提到的那样,它也可以正常工作 https://devcenter.heroku.com/articles/deploying-nodejs

但是当我跑步时

git push heroku master

我得到了上述错误。请帮助我解决这个问题。

谢谢

编辑

webpack.config.js

module.exports = (api) => {
    api.cache(true)
    return {
        ignore: [
            "babel.config.js",
            "dist",
            "package.json",
            "node_modules",
            '.babelrc'
        ]
    }
}

包.json

 "scripts": {
    "start": "npm run build && node dist/bin/www",
    "build": "rimraf dist/ && babel ./ --out-dir dist",
    "watch:dev": "nodemon"
  },

现在我通过更新应用程序结构来解决这个问题

"build": "rimraf dist/ && babel app/ --out-dir dist",

标签: node.jsherokuwebpackdeployment

解决方案


推荐阅读