Angular 从 v12 迁移到 v13:模块 <typescript> 只能使用“allowSyntheticDefaultImports”标志默认导入

use*_*344 5 angular

从 v12 升级到 v13 后,我在尝试 ng 服务时收到以下消息。\n如果我使用 v13 设置一个全新的项目,一切正常。我已经尝试将配置文件(tsconfig,angular.json,...)与 vimdiff 进行比较,但没有发现任何大的差异。

\n
Error: node_modules/@angular/compiler-cli/src/ngtsc/file_system/src/compiler_host.d.ts:9:8 - error TS1259: Module '"/project/node_modules/typescript/lib/typescript"' can only be default-imported using the 'allowSyntheticDefaultImports' flag\n\n9 import ts from 'typescript';\n         ~~\n\n  node_modules/typescript/lib/typescript.d.ts:7478:1\n    7478 export = ts;\n         ~~~~~~~~~~~~\n    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.\n\n\nError: node_modules/@angular/compiler-cli/src/ngtsc/file_system/src/logical.d.ts:9:8 - error TS1259: Module '"/project/node_modules/typescript/lib/typescript"' can only be default-imported using the 'allowSyntheticDefaultImports' flag\n\n9 import ts from 'typescript';\n         ~~\n\n  node_modules/typescript/lib/typescript.d.ts:7478:1\n    7478 export = ts;\n         ~~~~~~~~~~~~\n    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.\n\n\nError: node_modules/@angular/compiler-cli/src/ngtsc/file_system/src/util.d.ts:9:8 - error TS1259: Module '"/project/node_modules/typescript/lib/typescript"' can only be default-imported using the 'allowSyntheticDefaultImports' flag\n\n9 import ts from 'typescript';\n         ~~\n\n  node_modules/typescript/lib/typescript.d.ts:7478:1\n    7478 export = ts;\n         ~~~~~~~~~~~~\n    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.\n
Run Code Online (Sandbox Code Playgroud)\n

以下是已安装的软件包:

\n
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __ngcc_entry_points__.json@ extraneous\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular-devkit/build-angular@13.1.2\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/animations@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/cli@13.1.2\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/common@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/compiler-cli@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/compiler@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/core@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/forms@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/localize@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/platform-browser-dynamic@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/platform-browser@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @angular/router@13.1.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @types/jasmine@3.10.2\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 @types/node@12.20.37\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 eslint@8.6.0\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 jasmine-core@3.10.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 jasmine-spec-reporter@7.0.0\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 karma-chrome-launcher@3.1.0\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 karma-coverage@2.0.3\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 karma-firefox-launcher@2.1.2\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 karma-jasmine-html-reporter@1.7.0\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 karma-jasmine@4.0.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 karma@6.3.9\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 protractor@7.0.0\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 rxjs@7.4.0\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ts-node@8.3.0\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 tslib@2.3.1\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 typescript@4.4.4\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 webpack-bundle-analyzer@4.5.0\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 zone.js@0.11.4\n
Run Code Online (Sandbox Code Playgroud)\n

小智 9

您的 tsconfig.json 中的“compilerOptions”属性中是否有这些:

"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strictPropertyInitialization": false
Run Code Online (Sandbox Code Playgroud)