Angular SSR + cpanel + Node.js:未处理的Promise拒绝警告:SyntaxError:意外的符号 '??='"

前端开发 2026-07-10

我有一个新的Angular SSR项目,规格如下:

ts.config:

{
  "compileOnSave": false,
  "compilerOptions": {
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "skipLibCheck": true,
    "isolatedModules": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "lib": ["ES2022", "dom"]
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  },
  "files": [],
  "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.spec.json" }]
}

以及package.json中的这些库

{
  "name": "xxxx",
  "version": "0.1.16",
  "type": "module",
  "scripts": {
...
  },
  "private": true,
  "packageManager": "[email protected]",
  "dependencies": {
    "@angular/common": "^21.2.0",
    "@angular/compiler": "^21.2.0",
    "@angular/core": "^21.2.0",
    "@angular/forms": "^21.2.0",
    "@angular/platform-browser": "^21.2.0",
    "@angular/platform-server": "^21.2.0",
    "@angular/router": "^21.2.0",
    "@angular/ssr": "^21.2.3",
    "@commitlint/cli": "^20.5.0",
    "@commitlint/config-angular": "^20.5.0",
    "@ngx-translate/core": "^17.0.0",
    "@ngx-translate/http-loader": "^17.0.0",
    "@types/prompts": "^2.4.9",
    "basic-ftp": "^5.2.0",
    "commitlint": "^20.5.0",
    "dotenv": "^17.3.1",
    "express": "^5.1.0",
    "prompts": "^2.4.2",
    "rxjs": "~7.8.0",
    "ts-node": "^10.9.2",
    "tslib": "^2.3.0"
  },
  "overrides": {
    "undici": "^7.24.0"
  },
  "devDependencies": {
    "@angular-eslint/eslint-plugin": "^21.3.1",
    "@angular-eslint/eslint-plugin-template": "^21.3.1",
    "@angular-eslint/template-parser": "^21.3.1",
    "@angular/build": "^21.2.3",
    "@angular/cli": "^21.2.3",
    "@angular/compiler-cli": "^21.2.0",
    "@eslint/js": "^10.0.1",
    "@tailwindcss/postcss": "^4.1.12",
    "@types/express": "^5.0.1",
    "@types/node": "^20.17.19",
    "@typescript-eslint/eslint-plugin": "^8.57.1",
    "@typescript-eslint/parser": "^8.57.1",
    "eslint": "^10.1.0",
    "eslint-config-prettier": "^10.1.8",
    "eslint-plugin-jest": "^29.15.0",
    "eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
    "eslint-plugin-unused-imports": "^4.4.1",
    "husky": "^9.1.7",
    "jsdom": "^28.0.0",
    "postcss": "^8.5.3",
    "prettier": "^3.8.1",
    "tailwindcss": "^4.1.12",
    "typescript": "~5.9.2",
    "vitest": "^4.0.8"
  }
}

我本地的Node版本是 v24.14.1

在我的cPanel中,我把项目创建为Node.js项目,并将Node.Js版本设为24.13.0,并将应用启动文件指向我的 server.mjs

无法构建。我得到:503服务不可用

服务器会创建一个 stderr.log 文件,内容如下:

(node:138783) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:138783) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:138783) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:138933) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:138933) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:138933) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:139954) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:139954) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:139954) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:140014) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:140014) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:140014) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:140057) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:140057) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:140057) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:140277) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:140277) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:140277) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:140424) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:140424) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:140424) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:140491) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:140491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:140491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:145379) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:145379) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:145379) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:145419) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:145419) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:145419) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:145533) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:145533) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:145533) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:150304) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:150304) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:150304) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:150426) UnhandledPromiseRejectionWarning: Error: Not supported
    at startApplication (/usr/local/lsws/fcgi-bin/lsnodesm.js:49:18)
    at Object.<anonymous> (/usr/local/lsws/fcgi-bin/lsnodesm.js:16:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
(node:150426) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:150426) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2714599) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2714599) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2714599) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2714631) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2714631) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2714631) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2714671) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2714671) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2714671) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2716501) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2716501) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2716501) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2716542) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2716542) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2716542) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:1674686) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1674686) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1674686) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:1676723) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1676723) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1676723) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:1676800) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1676800) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1676800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:1678000) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18)
    at async link (internal/modules/esm/module_job.js:67:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1678000) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1678000) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

在我调查问题时,似乎是Node版本的问题,因为在版本15之前,'??=' 不是一个有效表达式。

但我看不出Node版本应该低于我现在使用的24的地方,无论是在本地编译还是在服务器上。

我在cPanel终端中的我的项目里执行node -v,当然得到的是24.13.0。

有没有人遇到过类似的问题,或者不降级Node.js版本就能解决吗?

解决方案

我解决了。

首先(为了保持初始设置)我把 tsconfig 设置为:

{
  "compileOnSave": false,
  "compilerOptions": {
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "skipLibCheck": true,
    "isolatedModules": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "ES2022",
    "useDefineForClassFields": false,
    "module": "preserve",
    "resolveJsonModule": true
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  },
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ]
}

这篇帖子中原本放的那个,在我第一次部署前做了一些“改进”后的修改。

有了它我重新尝试,错误消失了,但我仍然遇到503错误,而且没有日志。只有一个空日志文件。

所以,在Gemini的帮助以及大量内部日志的辅助下,我意识到问题在于NodeJs项目试图在主项目文件夹中找到构建产物中的chunk文件,而不是在dist文件夹中。

我在项目文件夹中创建了一个 index.js(在你有 .htaccessdist 文件夹的地方):

import path from 'node:path';
import { pathToFileURL } from 'node:url';
import http from 'node:http';

const serverFolder = path.join(process.cwd(), 'dist/my-project/server');
const serverFile = path.join(serverFolder, 'server.mjs');

console.warn("--- PROCESO DE ARRANQUE ---");

try {
    process.chdir(serverFolder);

    import(pathToFileURL(serverFile).href)
        .then((ngModule) => {
            console.warn("--- SERVIDOR ANGULAR SSR CARGADO ---");

            // Si cPanel no nos da un puerto num��rico, usamos el socket de Passenger
            const port = process.env.PORT || 'passenger'; 

            // Verificamos que Angular nos entreg�� su manejador de peticiones moderno
            if (typeof ngModule.reqHandler === 'function') {
                console.warn("Iniciando HTTP Server nativo con reqHandler de Angular...");

                // Creamos el servidor y le pasamos el control a Angular
                const server = http.createServer(ngModule.reqHandler);

                server.listen(port, () => {
                    console.warn(`[�0�7XITO TOTAL] Servidor escuchando peticiones en: ${port}`);
                });

            } else {
                console.warn("ERROR: reqHandler no es una funci��n. Exportaciones:", Object.keys(ngModule));
            }
        })
        .catch(err => {
            console.error("--- ERROR DENTRO DE SERVER.MJS ---");
            console.error(err);
        });

} catch (err) {
    console.error("--- ERROR AL CAMBIAR DIRECTORIO ---");
    console.error(err);
}

console.logs 是西班牙语的,不过你可以翻译它们 :D

最后一步:我把 index.js 设置为应用启动文件,而不是之前的 dist/my-project/server/server.mjs

就这样。现在一切都正常工作了。

P.S.当然别忘了在 angular.jsonallowedHosts 属性中填写你的域名。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章