【问题标题】:What is causing this next.js build error on the Vercel website?是什么导致 Vercel 网站上的 next.js 构建错误?
【发布时间】:2022-01-26 16:47:22
【问题描述】:

我有一个工作的 next.js 项目,我升级了 next.js (12.0.7)、Typescript (4.5.4) 和 pdfjs-dist (2.11.228) 以及其他库。该项目使用yarn dev 在本地完美运行,并使用yarn build 在本地完美构建。

但是,当我提交并推送到 Github 时。我在 Vercel 网站上得到以下构建输出:

Build error occurred
/vercel/path0/node_modules/pdfjs-dist/build/pdf.js:2358
    return this._jsActionsPromise ||= this._transport.getPageJSActions(this._pageIndex);
                                  ^^^
SyntaxError: Unexpected token '||='
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/vercel/path0/node_modules/@react-pdf-viewer/core/lib/cjs/core.min.js:1:94)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) {
  type: 'SyntaxError'
}
error Command failed with exit code 1.

显然这是一个意外,因为这似乎是有效的语法。

我的tsconfig.json 包含以下内容:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

我将不胜感激任何现场或指导。谢谢。

【问题讨论】:

  • ||= 不是有效语法,是在您的代码中还是在库中?
  • 它位于此处的 pdf.js 库中:github.com/mozilla/pdf.js

标签: typescript next.js vercel pdfjs


【解决方案1】:

逻辑或赋值运算符||= 似乎已添加到 ES2021 中。虽然我在本地运行的 Node 16 支持它,但我可以在 Vercel 配置的最新版本 Node 14 不支持它。

在 Vercel 支持 Node 15 或更高版本之前,我的解决方案是恢复到 pdf.js-dist 2.10.377。由于pdf查看器只在浏览器中使用,我也可以做一个动态导入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-27
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多