更新 npm 后 node_modules 中的错误?

Posted

技术标签:

【中文标题】更新 npm 后 node_modules 中的错误?【英文标题】:ERROR in node_modules after updating the npm? 【发布时间】:2021-02-20 13:48:57 【问题描述】:

这是我更新 npm 后遇到的错误,由于 [WDS] Disconnected 错误! Mozilla Firefox 控制台中的错误。这是有经验的开发者来解决的错误。


5 import firebase from 'firebase/app';
         ~~~~~~~~

  node_modules/firebase/index.d.ts:9710:1
    9710 export = firebase;
         ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the
'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/firestore/collection-group/collection-group.d.ts:2:8 - error TS1259: Module '"D:/apps/angularfs3/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

2 import firebase from 'firebase/app';
         ~~~~~~~~

  node_modules/firebase/index.d.ts:9710:1
    9710 export = firebase;
         ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the
'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/firestore/firestore.d.ts:9:8 - error TS1259: Module '"D:/apps/angularfs3/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

9 import firebase from 'firebase/app';
         ~~~~~~~~

  node_modules/firebase/index.d.ts:9710:1
    9710 export = firebase;
         ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the
'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/auth/auth.d.ts:4:8 - error TS1259: Module '"D:/apps/angularfs3/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

4 import firebase from 'firebase/app';
         ~~~~~~~~

  node_modules/firebase/index.d.ts:9710:1
    9710 export = firebase;
         ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the
'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/auth/auth.d.ts:12:14 - error TS2411: Property 'authState' of type 'Observable<any>' is not assignable to string index type 'Promise<any> & ((...args: unknown[]) => Promise<any>) & ((...args:
unknown[]) => any)'.

12     readonly authState: Observable<firebase.User | null>;
                ~~~~~~~~~
node_modules/@angular/fire/auth/auth.d.ts:16:14 - error TS2411: Property 'idToken' of type 'Observable<string>' is not assignable to string index type 'Promise<any> & ((...args: unknown[]) => Promise<any>) & ((...args: unknown[]) => any)'.

16     readonly idToken: Observable<string | null>;
                ~~~~~~~
node_modules/@angular/fire/auth/auth.d.ts:20:14 - error TS2411: Property 'user' of type 'Observable<any>' is
not assignable to string index type 'Promise<any> & ((...args: unknown[]) => Promise<any>) & ((...args: unknown[]) => any)'.

【问题讨论】:

尝试删除 node_modules 文件夹并再次运行 npm i 【参考方案1】:

您需要在tsconfig.jsoncompilerOptions 部分)中添加"allowSyntheticDefaultImports": true

https://www.typescriptlang.org/docs/handbook/compiler-options.html

【讨论】:

谢谢你,@Francesco!这就是我的 Angular 升级所需要的 谢谢@Francesco Colamonici

以上是关于更新 npm 后 node_modules 中的错误?的主要内容,如果未能解决你的问题,请参考以下文章

node_modules中依赖的版本更新

node_modules中依赖的版本更新

错误“由于 npm ERR 中的错​​误,您的缓存文件夹包含 root 拥有的文件!以前版本的 npm 已得到解决”

删除 node_modules 后如何解决 npm install 问题

Windows 10 下安装 npm 后全局 node_modules 和 npm-cache 文件夹的设置

删除 pacakge.json 和 node_modules 后 npm install 失败