如何修复目录导入 '@angular-devkit\build-angular\src\dev-server' 在更新 Angular 到版本 13 后不支持解析 ES 模块
How to fix Directory import '@angular-devkit\build-angular\src\dev-server' is not supported resolving ES modules after updating Angular to version 13
当 运行 ng serve
更新我的 angular 版本后出现以下错误:
An unhandled exception occurred: Directory import 'C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular-devkit\build-angular\src\dev-server' is not supported
resolving ES modules imported from C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
Did you mean to import C:/Users/xxx/Documents/desktop-server-client-app/desktop/server/client/node_modules/@angular-devkit/build-angular/src/dev-server/index.js?
See "C:\Users\xxx\AppData\Local\Temp\ng-TMJqg5\angular-errors.log" for further details.
日志输出:
[error] Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular-devkit\build-angular\src\dev-server' is not supported resolving ES modules imported from C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
Did you mean to import C:/Users/xxx/Documents/desktop-server-client-app/desktop/server/client/node_modules/@angular-devkit/build-angular/src/dev-server/index.js?
at finalizeResolution (internal/modules/esm/resolve.js:272:17)
at moduleResolve (internal/modules/esm/resolve.js:699:10)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
at Loader.resolve (internal/modules/esm/loader.js:85:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
at Loader.import (internal/modules/esm/loader.js:164:28)
at importModuleDynamically (internal/modules/cjs/loader.js:1006:27)
at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
at eval (eval at loadEsmModule (C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:195:12), <anonymous>:3:1)
at loadEsmModule (C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:195:68)
有人可以向我解释这个错误的含义以及我该如何解决吗?在我看来,这是某种我无能为力的兼容性问题。到目前为止,我的 angular 项目只包含一些样板代码,所以这应该不是问题。
编辑:我的版本如下:
Node: 14.15.0
npm: 6.14.8
Angular: 13.2.4
@angular-devkit/architect: 0.1202.16
@angular-devkit/build-angular: 12.2.16
@angular-devkit/core: 12.2.16
@angular-devkit/schematics: 13.2.5
@angular/cdk: 12.2.13
@angular/cli: 13.2.5
@angular/material: 12.2.13
@schematics/angular: 13.2.5
rxjs: 6.6.7
typescript: 4.5.5
我遇到这个问题是因为我使用 --legacy-peer-deps
标志将我的项目更新为 Angular 13。因此,package.json
.
中仍然存在旧的依赖项
确保您拥有与抛出的错误相关的合适的包版本。在您的确切情况下,尝试更改
"@angular-devkit/build-angular": "~12.2.16"
至 "@angular-devkit/build-angular": "~13.2.5"
然后 运行 npm install
.
当 运行 ng serve
更新我的 angular 版本后出现以下错误:
An unhandled exception occurred: Directory import 'C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular-devkit\build-angular\src\dev-server' is not supported
resolving ES modules imported from C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
Did you mean to import C:/Users/xxx/Documents/desktop-server-client-app/desktop/server/client/node_modules/@angular-devkit/build-angular/src/dev-server/index.js?
See "C:\Users\xxx\AppData\Local\Temp\ng-TMJqg5\angular-errors.log" for further details.
日志输出:
[error] Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular-devkit\build-angular\src\dev-server' is not supported resolving ES modules imported from C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
Did you mean to import C:/Users/xxx/Documents/desktop-server-client-app/desktop/server/client/node_modules/@angular-devkit/build-angular/src/dev-server/index.js?
at finalizeResolution (internal/modules/esm/resolve.js:272:17)
at moduleResolve (internal/modules/esm/resolve.js:699:10)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
at Loader.resolve (internal/modules/esm/loader.js:85:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
at Loader.import (internal/modules/esm/loader.js:164:28)
at importModuleDynamically (internal/modules/cjs/loader.js:1006:27)
at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
at eval (eval at loadEsmModule (C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:195:12), <anonymous>:3:1)
at loadEsmModule (C:\Users\xxx\Documents\desktop-server-client-app\desktop\server\client\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:195:68)
有人可以向我解释这个错误的含义以及我该如何解决吗?在我看来,这是某种我无能为力的兼容性问题。到目前为止,我的 angular 项目只包含一些样板代码,所以这应该不是问题。
编辑:我的版本如下:
Node: 14.15.0
npm: 6.14.8
Angular: 13.2.4
@angular-devkit/architect: 0.1202.16
@angular-devkit/build-angular: 12.2.16
@angular-devkit/core: 12.2.16
@angular-devkit/schematics: 13.2.5
@angular/cdk: 12.2.13
@angular/cli: 13.2.5
@angular/material: 12.2.13
@schematics/angular: 13.2.5
rxjs: 6.6.7
typescript: 4.5.5
我遇到这个问题是因为我使用 --legacy-peer-deps
标志将我的项目更新为 Angular 13。因此,package.json
.
确保您拥有与抛出的错误相关的合适的包版本。在您的确切情况下,尝试更改
"@angular-devkit/build-angular": "~12.2.16"
至 "@angular-devkit/build-angular": "~13.2.5"
然后 运行 npm install
.