I have an Aurelia project in a NET Core project. I am able to build the project using Aurelia CLI but the Visual Studio build fails with the following TypeScript errors:
Build:Cannot find name 'RequestInit'.
Build:Cannot find name 'Request'.
Build:Cannot find name 'Response'.
Most of these errors are coming from the aurelia-fetch-client
.
Next I try to fix the problem by installing the package @types/whatwg-fetch
. The Visual Studio errors disappear, but now the Aurelia CLI will not build. The errors thrown are:
Cannot redeclare block-scoped variable 'fetch'.
Duplicate identifier 'HeadersInit'.
Duplicate identifier 'Headers'.
Duplicate identifier 'RequestInfo'.
Duplicate identifier 'Request'.
Duplicate identifier 'Response'.
... and many more duplicate identifiers.
The collisions are in whatwg-fetch and lib.dom.d.ts. How to I get both builds back to green?
Update
I see Request definition in lib.dom.d.ts
so I feel that Aurelia CLI is working and Visual Studio is broken. Why would Visual Studio not pick up these typings when I have the following tsconfig:
"compileOnSave": false,
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"module": "amd",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"lib": ["es2017", "dom"]
},
"exclude": [
"node_modules",
"aurelia_project"
],
"filesGlob": [
"./src/**/*.ts",
"./test/**/*.ts",
"./custom_typings/**/*.d.ts"
]
Update 2 If I add the lib.dom.d.ts file to the files array in the tsconfig, the errors disappear in Visual Studio.
"files": [
"./node_modules/typescript/lib/lib.es2017.d.ts",
"./node_modules/typescript/lib/lib.es2017.object.d.ts",
"./node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts",
"./node_modules/typescript/lib/lib.es2017.string.d.ts",
"./node_modules/typescript/lib/lib.dom.d.ts"
]
There must be a better way.