简体   繁体   English

@babel/types 在 Angular 8.2.14 中的 ng build 命令上构建错误

[英]@babel/types build errors on ng build command in Angular 8.2.14

I am getting the below errors when I run the command ' ng build ' for my Angular App.当我为我的 Angular 应用程序运行命令“ ng build ”时,出现以下错误。

ERROR in ../node_modules/@types/babel-types/index.d.ts:1769:96 - error TS1144: '{' or ';' expected.

1769 export function assertArrayExpression(node: object | null | undefined, opts?: object): asserts node is ArrayExpression;
                                                                                                    ~~~~
../node_modules/@types/babel-types/index.d.ts:1769:101 - error TS1005: ';' expected.

1769 export function assertArrayExpression(node: object | null | undefined, opts?: object): asserts node is ArrayExpression;
                                                                                                         ~~
../node_modules/@types/babel-types/index.d.ts:1769:104 - error TS1005: ';' expected.

1769 export function assertArrayExpression(node: object | null | undefined, opts?: object): asserts node is ArrayExpression;
                                                                                                            ~~~~~~~~~~~~~~~
../node_modules/@types/babel-types/index.d.ts:1770:101 - error TS1144: '{' or ';' expected.

1770 export function assertAssignmentExpression(node: object | null | undefined, opts?: object): asserts node is AssignmentExpression;
                                                                                                         ~~~~
../node_modules/@types/babel-types/index.d.ts:1770:106 - error TS1005: ';' expected.

1770 export function assertAssignmentExpression(node: object | null | undefined, opts?: object): asserts node is AssignmentExpression;

Here is my Angular and Node js version info:这是我的 Angular 和 Node js 版本信息:

Angular CLI: 8.3.29

Node: 16.13.1

OS: win32 x64

Angular: 8.2.14

npm 8.1.2

Previously, I was using Node 12 and it was building successfully.以前,我使用的是 Node 12,它正在成功构建。 after upgrading to Node 16 I am facing issues as above.升级到 Node 16 后,我遇到了上述问题。

"devDependencies": {
    "@angular-devkit/build-angular": "~0.803.25",
    "@angular/cli": "~8.3.25",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "12.7.3",
    "apply-loader": "^2.0.0",
    "codelyzer": "^5.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "pug": "^2.0.3",
    "pug-loader": "^2.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.5.3"
  }

Do I need to upgrade any package versions?我是否需要升级任何 package 版本? Or is there any compatibility issues with Node 16或者 Node 16 是否存在兼容性问题

The issue is that angular v8 has 100s of dependencies and fair few of these are not compatible with node v16 (or with package-lock.json v2).问题是 angular v8 有 100 个依赖项,其中相当少的依赖项与节点 v16(或 package-lock.json v2)不兼容。 If you need to upgrade node, you might be better off also upgrading angular.如果您需要升级节点,最好同时升级 angular。

The best/easiest is to pace the upgrade of your dependencies whilst upgrading node in steps.最好/最简单的方法是在逐步升级节点的同时调整依赖项的升级速度。 Installing node 14, upgrade dependencies, then install v16 and do it again.安装node 14,升级依赖,然后安装v16,再做一遍。

I also suggest you downgrade your npm to v7 as v8+ will upgrade your package-lock.json to v2.我还建议您将 npm 降级到 v7,因为 v8+ 会将您的 package-lock.json 升级到 v2。 This can complicate things whilst doing the upgrades.在进行升级时,这会使事情复杂化。 After upgrading your dependencies you can always upgrade your npm to the latest and then upgrade your package-lock to v2.升级依赖项后,您始终可以将 npm 升级到最新版本,然后将 package-lock 升级到 v2。

I answer a similar question the other day it might also help you: https://stackoverflow.com/a/68159069/4604645前几天我回答了一个类似的问题,它也可能对您有所帮助: https://stackoverflow.com/a/68159069/4604645

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM