Reputation: 313
Getting following error after updating app from Angular 5 to 7, using ng update --all --force to update all the dependencies.
ERROR in node_modules/@types/node/globals.d.ts(196,5): error TS2300: Duplicate identifier 'resolve'. src/typings.d.ts(12,3): error TS2300: Duplicate identifier 'resolve'.
Tried adding this to tsconfig.json file:
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts",
"typings/index.d.ts",
"node_modules/@types/node/globals.d.ts"
]
and this to package.json:
"postinstall": "shx rm -rf node_modules/@types/node && echo 'workaround for libs importing @types/node on browser environment'"
then deleted node modules and did fresh install. Nothing has helped.
this is from 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;
and this is from 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;
}
Upvotes: 1
Views: 5769
Reputation: 57146
This is happening because two Node modules define "resolve".
You can fix this by doing this:
tsconfig.app.json
{
"compilerOptions": {
types: [] // you can list the types you want to use here
}
}
You probably want to do the same to tsconfig.spec.json
if you are unit testing.
Upvotes: 0
Reputation: 1083
I was receiving a similar error message. I have fixed installing typescript in my project:
npm i -D typescript
Typescript was installed globally with a previous version not corresponding with @types/node library version in the project
Upvotes: 1