[英]React/ServerlessSyntaxError: Unexpected token '.' - if (options?.CAPACITY) {
對於我的無服務器反應程序,瀏覽器只是說:
SyntaxError: 意外的標記 '.'
下面是我在 AWS 上的 Cloudwatch 日志。 如果我更改我的程序,並得到這樣的錯誤,而不是在我的代碼中,我應該采用什么方法來解決?
2023-01-21T21:56:10.862-06:00
Copy
2023-01-22T03:56:10.862Z bcad1fe4-3046-4d00-a7c3-853024fd4cc1 ERROR /var/task/630.js:80
if (options?.CAPACITY) {
^
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.__webpack_require__.f.require (/var/task/webpack:/serverless-react-boilerplate/webpack/runtime/require chunk loading:29:1)
at /var/task/webpack:/serverless-react-boilerplate/webpack/runtime/ensure chunk:6:1
at Array.reduce (<anonymous>)
2023-01-22T03:56:10.862Z bcad1fe4-3046-4d00-a7c3-853024fd4cc1 ERROR /var/task/630.js:80 if (options?.CAPACITY) { ^ SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.__webpack_require__.f.require (/var/task/webpack:/serverless-react-boilerplate/webpack/runtime/require chunk loading:29:1) at /var/task/webpack:/serverless-react-boilerplate/webpack/runtime/ensure chunk:6:1 at Array.reduce (<anonymous>)
這種語法options?.CAPACITY
被稱為Optional chaining 。 看起來您的本地設置支持它,但您在 AWS 上的設置不支持。
您需要確保使用支持可選鏈接的正確 package 版本。
對於 NodeJs,您需要使用版本>=14.0.0
( Ref )
對於 Webpack,您需要使用版本>=5
( Ref )
對於 Babel,您需要使用>=7.8.0
的版本(參考)
如果您使用的是create-react-app
,則需要使用>=3.3.0
的版本( 參考)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.