在heroku上部署Nodejs应用时出现BABEL_PARSE_ERROR

zzwlnbp8  于 2023-06-22  发布在  Node.js
关注(0)|答案(1)|浏览(166)

我正在heroku服务器上部署node js应用程序。我正在使用webpack for 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'
        ]
    }
}

package.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",
z6psavjg

z6psavjg1#

这是如何解决的?有所有的预置和插件,并使用Babelv7.看不出这是怎么打破的
集合-x
node_modules/.bin/tsc -p ./tsconfig.base.json && node_modules/.bin/babel ./src/helpers --out-dir ./lib --extensions '.ts,.tsx,.js,.jsx' --copy-files --ignore**/tests//*,/fixtures//*,/mocks//*,/*.d.ts $1

相关问题