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

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

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

问题

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

  1. 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.

  1. 9:00:52 PM: $ npm run build
  2. 9:00:52 PM: > ace-gymnastics@0.1.0 build /opt/build/repo
  3. 9:00:52 PM: > react-scripts build
  4. 9:00:53 PM: /opt/build/repo/node_modules/eslint-webpack-plugin/node_modules/jest-worker/build/index.js:110
  5. 9:00:53 PM: _ending;
  6. 9:00:53 PM: ^
  7. 9:00:53 PM: SyntaxError: Unexpected token ;
  8. 9:00:53 PM: at Module._compile (internal/modules/cjs/loader.js:723:23)
  9. 9:00:53 PM: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
  10. 9:00:53 PM: at Module.load (internal/modules/cjs/loader.js:653:32)
  11. 9:00:53 PM: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
  12. 9:00:53 PM: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
  13. 9:00:53 PM: at Module.require (internal/modules/cjs/loader.js:692:17)
  14. 9:00:53 PM: at require (internal/modules/cjs/helpers.js:25:18)
  15. 9:00:53 PM: at Object.<anonymous> (/opt/build/repo/node_modules/eslint-webpack-plugin/dist/getESLint.js:9:5)
  16. 9:00:53 PM: at Module._compile (internal/modules/cjs/loader.js:778:30)
  17. 9:00:53 PM: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
  18. 9:00:53 PM: npm ERR! code ELIFECYCLE
  19. 9:00:53 PM: npm ERR! errno 1
  20. 9:00:53 PM: npm ERR! ace-gymnastics@0.1.0 build: `react-scripts build`
  21. 9:00:53 PM: npm ERR! Exit status 1
  22. 9:00:53 PM: npm ERR!
  23. 9:00:53 PM: npm ERR! Failed at the ace-gymnastics@0.1.0 build script.
  24. 9:00:53 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  25. 9:00:53 PM: npm ERR! A complete log of this run can be found in:
  26. 9:00:53 PM: npm ERR! /opt/buildhome/.npm/_logs/2023-01-05T02_00_53_829Z-debug.log
  27. 9:00:53 PM:
  28. 9:00:53 PM: "build.command" failed
  29. 9:00:53 PM: ────────────────────────────────────────────────────────────────
  30. 9:00:53 PM:
  31. 9:00:53 PM: Error message
  32. 9:00:53 PM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
  33. 9:00:53 PM:
  34. 9:00:53 PM: Error location
  35. 9:00:53 PM: In Build command from Netlify app:
  36. 9:00:53 PM: npm run build
  37. 9:00:53 PM:
  38. 9:00:55 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
  39. 9:00:53 PM: Resolved config
  40. 9:00:53 PM: build:
  41. 9:00:53 PM: command: npm run build
  42. 9:00:53 PM: commandOrigin: ui
  43. 9:00:53 PM: environment:
  44. 9:00:53 PM: - REACT_APP_GA_TRACKING
  45. 9:00:53 PM: - REACT_APP_ORGID
  46. 9:00:53 PM: publish: /opt/build/repo/build
  47. 9:00:53 PM: publishOrigin: ui
  48. 9:00:54 PM: Caching artifacts
  49. 9:00:54 PM: Started saving node modules
  50. 9:00:54 PM: Finished saving node modules
  51. 9:00:54 PM: Started saving build plugins
  52. 9:00:54 PM: Finished saving build plugins
  53. 9:00:54 PM: Started saving pip cache
  54. 9:00:54 PM: Finished saving pip cache
  55. 9:00:54 PM: Started saving emacs cask dependencies
  56. 9:00:54 PM: Finished saving emacs cask dependencies
  57. 9:00:54 PM: Started saving maven dependencies
  58. 9:00:54 PM: Finished saving maven dependencies
  59. 9:00:54 PM: Started saving boot dependencies
  60. 9:00:54 PM: Finished saving boot dependencies
  61. 9:00:54 PM: Started saving rust rustup cache
  62. 9:00:54 PM: Finished saving rust rustup cache
  63. 9:00:54 PM: Started saving go dependencies
  64. 9:00:54 PM: Finished saving go dependencies
  65. 9:00:55 PM: Cached ruby version 2.6.2
  66. 9:00:55 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
  67. 9:00:55 PM: Failing build: Failed to build site
  68. 9:00:55 PM: Finished processing build request in 53.449896862s
  69. <details>
  70. <summary>英文:</summary>
  71. I am deploying to netlify and I keep running into this error

SyntaxError: Unexpected token ;

  1. 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

  1. </details>
  2. # 答案1
  3. **得分**: 2
  4. 正如您在评论中提到的,问题是Netlify的npm版本要高得多,超过了您的本地环境,因此您的代码某些语法已被弃用,不再被(更新的)npm理解。
  5. 建议升级您的本地npm版本,但如果现在不可能,您可以降级Netlify的npm版本。
  6. 为了设置Netlify的npm版本,您可以使用`NODE_VERSION`环境变量。
  7. 前往`https://app.netlify.com/sites/<site-name>/settings/env#environment-variables`,添加`NODE_VERSION`变量,并将其设置为您的本地npm版本。
  8. <details>
  9. <summary>英文:</summary>
  10. 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.
  11. 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.
  12. In order to set Netlify&#39;s npm version, you can use `NODE_VERSION` environment variable.
  13. 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.
  14. </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:

确定