node.js - 错误node_modules/@types/node/globals.d.ts(196,5) errorTS2300 : Duplicate identifier 'resolve' src/typings. d.ts(12,3)重复标识符 'resolve'

标签 node.js angular typescript

使用 ng update --all --force 更新所有依赖项,将应用程序从 Angular 5 更新到 7 后出现以下错误。

node_modules/@types/node/globals.d.ts(196,5) 中出现错误:错误 TS2300:重复的标识符“解析”。 src/typings.d.ts(12,3):错误 TS2300:重复的标识符“解析”。

尝试将其添加到 tsconfig.json 文件中:

"exclude": [
      "node_modules",
      "typings/main",
      "typings/main.d.ts",
      "typings/index.d.ts",
      "node_modules/@types/node/globals.d.ts"
    ]

并将其添加到 package.json: "postinstall": "shx rm -rf node_modules/@types/node && echo '在浏览器环境中导入 @types/node 的库的解决方法'"

然后删除 Node 模块并进行全新安装。没有任何帮助。

这来自node_modules/@types/node/globals.d.ts

interface NodeRequireFunction {
    /* tslint:disable-next-line:callable-types */
    (id: string): any;
}

interface NodeRequire extends NodeRequireFunction {
    resolve: RequireResolve; <- duplicate resolve
    cache: any;
    /**
     * @deprecated
     */
    extensions: NodeExtensions;
    main: NodeModule | undefined;
}

interface RequireResolve {
    (id: string, options?: { paths?: string[]; }): string;
    paths(request: string): string[] | null;
}

interface NodeExtensions {
    '.js': (m: NodeModule, filename: string) => any;
    '.json': (m: NodeModule, filename: string) => any;
    '.node': (m: NodeModule, filename: string) => any;
    [ext: string]: (m: NodeModule, filename: string) => any;
}

declare var require: NodeRequire;

这是来自typings.d.ts:

declare var module: NodeModule;
interface NodeModule {
  id: string;
}
declare var CSSstring: string;
interface NodeRequire {
  cache: any;
  extensions: NodeExtensions;
  main: NodeModule;
  (id: string): any;
  resolve(id: string): string;    <- duplicate resolve
}

declare var require: NodeRequire;
declare module '*.json' {
    const value: any;
    export default value;
}

最佳答案

我收到了类似的错误消息。我已经修复了在我的项目中安装 typescript 的问题:

npm i -D typescript

Typescript 已全局安装,其先前版本与项目中的 @types/node 库版本不对应

关于node.js - 错误node_modules/@types/node/globals.d.ts(196,5) errorTS2300 : Duplicate identifier 'resolve' src/typings. d.ts(12,3)重复标识符 'resolve',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55638660/

相关文章:

javascript - Angular 中 ngOnInit() 动态创建类字段

angular - ionic 电容器本地通知

node.js - 在没有 GMail 的 nodejs 中使用 nodemailer 的 SMTP

python - Azure VM 似乎会终止长时间运行的 MySql 查询

javascript - 使用 AOT 编译创建可重用的动画

Angular 2 http 没有捕获连接被拒绝的错误

typescript - vue 3composition api props函数无法调用可能为 'undefined'的对象

angular - 将数据传递给子组件 Angular(从 Web 服务接收的数据不附加在子组件上)

node.js - Nodejs 在生成子进程时忽略 cwd

node.js - 在 NodeJS 中列出 Azure 中的所有资源