如何修复 Netlify 构建错误 “SyntaxError: Unexpected token ;”

huangapple go评论103阅读模式
英文:

How to fix netlify build error of "SyntaxError: Unexpected token ;"

问题

I am deploying to netlify and I keep running into this error

SyntaxError: Unexpected token ;

My master branch deploys with no errors but my developer branch keeps having the same issue. Here is a picture of my log where it is failing. I can also npm run build locally and there are no errors.

9:00:52 PM: $ npm run build
9:00:52 PM: > ace-gymnastics@0.1.0 build /opt/build/repo
9:00:52 PM: > react-scripts build
9:00:53 PM: /opt/build/repo/node_modules/eslint-webpack-plugin/node_modules/jest-worker/build/index.js:110
9:00:53 PM:   _ending;
9:00:53 PM:          ^
9:00:53 PM: SyntaxError: Unexpected token ;
9:00:53 PM:     at Module._compile (internal/modules/cjs/loader.js:723:23)
9:00:53 PM:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
9:00:53 PM:     at Module.load (internal/modules/cjs/loader.js:653:32)
9:00:53 PM:     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
9:00:53 PM:     at Function.Module._load (internal/modules/cjs/loader.js:585:3)
9:00:53 PM:     at Module.require (internal/modules/cjs/loader.js:692:17)
9:00:53 PM:     at require (internal/modules/cjs/helpers.js:25:18)
9:00:53 PM:     at Object.<anonymous> (/opt/build/repo/node_modules/eslint-webpack-plugin/dist/getESLint.js:9:5)
9:00:53 PM:     at Module._compile (internal/modules/cjs/loader.js:778:30)
9:00:53 PM:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
9:00:53 PM: npm ERR! code ELIFECYCLE
9:00:53 PM: npm ERR! errno 1
9:00:53 PM: npm ERR! ace-gymnastics@0.1.0 build: `react-scripts build`
9:00:53 PM: npm ERR! Exit status 1
9:00:53 PM: npm ERR!
9:00:53 PM: npm ERR! Failed at the ace-gymnastics@0.1.0 build script.
9:00:53 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
9:00:53 PM: npm ERR! A complete log of this run can be found in:
9:00:53 PM: npm ERR!     /opt/buildhome/.npm/_logs/2023-01-05T02_00_53_829Z-debug.log
9:00:53 PM: ​
9:00:53 PM:   "build.command" failed
9:00:53 PM: ────────────────────────────────────────────────────────────────
9:00:53 PM: ​
9:00:53 PM:   Error message
9:00:53 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
9:00:53 PM: ​
9:00:53 PM:   Error location
9:00:53 PM:   In Build command from Netlify app:
9:00:53 PM:   npm run build
9:00:53 PM: ​
9:00:55 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
9:00:53 PM:   Resolved config
9:00:53 PM:   build:
9:00:53 PM:     command: npm run build
9:00:53 PM:     commandOrigin: ui
9:00:53 PM:     environment:
9:00:53 PM:       - REACT_APP_GA_TRACKING
9:00:53 PM:       - REACT_APP_ORGID
9:00:53 PM:     publish: /opt/build/repo/build
9:00:53 PM:     publishOrigin: ui
9:00:54 PM: Caching artifacts
9:00:54 PM: Started saving node modules
9:00:54 PM: Finished saving node modules
9:00:54 PM: Started saving build plugins
9:00:54 PM: Finished saving build plugins
9:00:54 PM: Started saving pip cache
9:00:54 PM: Finished saving pip cache
9:00:54 PM: Started saving emacs cask dependencies
9:00:54 PM: Finished saving emacs cask dependencies
9:00:54 PM: Started saving maven dependencies
9:00:54 PM: Finished saving maven dependencies
9:00:54 PM: Started saving boot dependencies
9:00:54 PM: Finished saving boot dependencies
9:00:54 PM: Started saving rust rustup cache
9:00:54 PM: Finished saving rust rustup cache
9:00:54 PM: Started saving go dependencies
9:00:54 PM: Finished saving go dependencies
9:00:55 PM: Cached ruby version 2.6.2
9:00:55 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:00:55 PM: Failing build: Failed to build site
9:00:55 PM: Finished processing build request in 53.449896862s

<details>
<summary>英文:</summary>

I am deploying to netlify and I keep running into this error 

SyntaxError: Unexpected token ;

My master branch deploys with no errors but my developer branch keeps having the same issue. Here is a picture of my log where it is failing. I can also npm run build locally and there are no errors. 

9:00:52 PM: $ npm run build
9:00:52 PM: > ace-gymnastics@0.1.0 build /opt/build/repo
9:00:52 PM: > react-scripts build
9:00:53 PM: /opt/build/repo/node_modules/eslint-webpack-plugin/node_modules/jest-worker/build/index.js:110
9:00:53 PM: _ending;
9:00:53 PM: ^
9:00:53 PM: SyntaxError: Unexpected token ;
9:00:53 PM: at Module._compile (internal/modules/cjs/loader.js:723:23)
9:00:53 PM: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
9:00:53 PM: at Module.load (internal/modules/cjs/loader.js:653:32)
9:00:53 PM: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
9:00:53 PM: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
9:00:53 PM: at Module.require (internal/modules/cjs/loader.js:692:17)
9:00:53 PM: at require (internal/modules/cjs/helpers.js:25:18)
9:00:53 PM: at Object.<anonymous> (/opt/build/repo/node_modules/eslint-webpack-plugin/dist/getESLint.js:9:5)
9:00:53 PM: at Module._compile (internal/modules/cjs/loader.js:778:30)
9:00:53 PM: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
9:00:53 PM: npm ERR! code ELIFECYCLE
9:00:53 PM: npm ERR! errno 1
9:00:53 PM: npm ERR! ace-gymnastics@0.1.0 build: react-scripts build
9:00:53 PM: npm ERR! Exit status 1
9:00:53 PM: npm ERR!
9:00:53 PM: npm ERR! Failed at the ace-gymnastics@0.1.0 build script.
9:00:53 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
9:00:53 PM: npm ERR! A complete log of this run can be found in:
9:00:53 PM: npm ERR! /opt/buildhome/.npm/_logs/2023-01-05T02_00_53_829Z-debug.log
9:00:53 PM: ​
9:00:53 PM: "build.command" failed
9:00:53 PM: ────────────────────────────────────────────────────────────────
9:00:53 PM: ​
9:00:53 PM: Error message
9:00:53 PM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
9:00:53 PM: ​
9:00:53 PM: Error location
9:00:53 PM: In Build command from Netlify app:
9:00:53 PM: npm run build
9:00:53 PM: ​
9:00:55 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
9:00:53 PM: Resolved config
9:00:53 PM: build:
9:00:53 PM: command: npm run build
9:00:53 PM: commandOrigin: ui
9:00:53 PM: environment:
9:00:53 PM: - REACT_APP_GA_TRACKING
9:00:53 PM: - REACT_APP_ORGID
9:00:53 PM: publish: /opt/build/repo/build
9:00:53 PM: publishOrigin: ui
9:00:54 PM: Caching artifacts
9:00:54 PM: Started saving node modules
9:00:54 PM: Finished saving node modules
9:00:54 PM: Started saving build plugins
9:00:54 PM: Finished saving build plugins
9:00:54 PM: Started saving pip cache
9:00:54 PM: Finished saving pip cache
9:00:54 PM: Started saving emacs cask dependencies
9:00:54 PM: Finished saving emacs cask dependencies
9:00:54 PM: Started saving maven dependencies
9:00:54 PM: Finished saving maven dependencies
9:00:54 PM: Started saving boot dependencies
9:00:54 PM: Finished saving boot dependencies
9:00:54 PM: Started saving rust rustup cache
9:00:54 PM: Finished saving rust rustup cache
9:00:54 PM: Started saving go dependencies
9:00:54 PM: Finished saving go dependencies
9:00:55 PM: Cached ruby version 2.6.2
9:00:55 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:00:55 PM: Failing build: Failed to build site
9:00:55 PM: Finished processing build request in 53.449896862s


</details>


# 答案1
**得分**: 2

正如您在评论中提到的,问题是Netlify的npm版本要高得多,超过了您的本地环境,因此您的代码某些语法已被弃用,不再被(更新的)npm理解。

建议升级您的本地npm版本,但如果现在不可能,您可以降级Netlify的npm版本。

为了设置Netlify的npm版本,您可以使用`NODE_VERSION`环境变量。

前往`https://app.netlify.com/sites/<site-name>/settings/env#environment-variables`,添加`NODE_VERSION`变量,并将其设置为您的本地npm版本。

<details>
<summary>英文:</summary>

As you mentioned in your comment, the issue is Netlify&#39;s npm version is much higher than your local environment and thus some syntax of your code is deprecated and no longer understood by the (newer) npm.

It is recommended to upgrade your local npm version, but if it&#39;s not possible right now, you can downgrade Netlify&#39;s npm version.

In order to set Netlify&#39;s npm version, you can use `NODE_VERSION` environment variable.

Go to `https://app.netlify.com/sites/&lt;site-name&gt;/settings/env#environment-variables` and add `NODE_VERSION` variable and set it as your local npm version.

</details>



huangapple
  • 本文由 发表于 2023年1月5日 10:13:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75013231.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定