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

时间:2019-04-11 18:01:45

标签: node.js angular typescript

使用ng update --all --force将应用程序从Angular 5更新为7后,出现以下错误。

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

试图将其添加到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 'workaround for libs importing @types/node on browser environment'"

然后删除节点模块并重新安装。没有任何帮助。

这是来自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;

这是来自types.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;
}

2 个答案:

答案 0 :(得分:0)

这正在发生,因为coz 2节点模块定义了“解决”

您可以通过以下方法解决此问题:

tsconfig.app.json

{
  "compilerOptions": {
    types: [] // you can list the types you want to use here
  } 
}

如果您正在进行单元测试,则可能要对tsconfig.spec.json做同样的事情。

答案 1 :(得分:0)

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

npm i -D typescript

Typescript是在全球范围内安装的,其先前版本与项目中的@ types / node库版本不对应