[英]Why do I get a UserCodeSyntaxError when I have no syntax error in my code?
[英]Why do i get a optional chaining syntax error when my code is deployed but not locally if they are using the same node version?
最近我升級了各種包(nextJS 和 Apollo),所以不得不根據需要將我的節點版本升級到 16.13.1。 我正在使用 github 構建工作流程並將節點版本指定為 16.13.1。 完成構建后,它會部署,但當 api 調用試圖命中 apollo 時,我收到 500 個錯誤。 我懷疑我的阿波羅服務器沒有建立。 當我查看控制台日志時,我可以看到關於可選鏈接的錯誤,我懷疑它正在阻止 apollo 服務器正確構建,因此在嘗試查詢時導致 500 運行時錯誤。 可選鏈接應該在這個版本的節點上工作,它在本地運行時也是如此,所以為什么不在部署時呢?
任何調試建議? 我認為追求下面的問題代碼是一個紅色的鯡魚 fyi
從控制台復制的錯誤:
2023-01-17T11:45:58.249754172Z /home/site/wwwroot/.next/server/pages/api/graphql.js:5515
2023-01-17T11:45:58.249791573Z if (!response?.record) return null;
2023-01-17T11:45:58.249796773Z ^
2023-01-17T11:45:58.249800473Z
2023-01-17T11:45:58.249803973Z SyntaxError: Unexpected token '.'
2023-01-17T11:45:58.249807573Z at wrapSafe (internal/modules/cjs/loader.js:915:16)
2023-01-17T11:45:58.249811173Z at Module._compile (internal/modules/cjs/loader.js:963:27)
2023-01-17T11:45:58.249814773Z at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
工作流文件(僅顯示節點和構建步驟)
on:
push:
branches:
- test
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/cache@v1
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}
- name: Set up Node.js version
uses: actions/setup-node@main
with:
node-version: '16.13.1'
- name: npm install, build, and test
run: |
npm install
npm run build
npm run lint:eslint
npm run test:ci
嘗試更改節點和語法的版本。 使用節點版本“16”、“14”、“12.x”、“16.x”。 嘗試使用不同的操作/設置節點版本,包括“v1”、“v2”、“v3”。 嘗試在沒有緩存步驟的情況下進行構建(actions/cache@v1 with.....等)——這實際上會導致部署時發生內部服務器錯誤失敗,而且我更廣泛的 nextjs 應用程序頁面似乎也失敗了。 控制台日志似乎表明“nullish coalescing operator”的問題是這種情況的原因。
我發現我在其中托管我的應用程序的容器有一個設置為節點 12 的目標框架配置設置。當我將其更新到節點 16 時,構建工作正常。
請參閱此處的帖子以更改 Azure 應用程序服務中的配置: 更改 Azure 應用程序中的目標框架 web 應用程序
總之,該應用程序已在節點 16 中成功構建並作為節點 16 應用程序部署到應用程序服務,但無論容器在做什么,它都是在節點 12 中執行的,因此抱怨節點 12 中不可用的語法,例如可選鏈接和無效合並。
我不確定此設置是否僅特定於 Azure 所以希望這可以幫助某人,至少在您遇到類似問題時執行檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.