1

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'.

Visual Studio errors

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.

Jonathan Eckman
  • 2,071
  • 3
  • 23
  • 49

2 Answers2

0

It looks like a lot of the same errors I've managed to solve earlier on Stack Overflow, please take a look here and see if this could be of any use to you: How to create aurelia typescript project with vs2017rc

Perhaps you have solved most of the issues in the link already or maybe this does not apply to your specific situation with Aurelia CLI, but-- This command: npm install typescript@2.1.5 --save has helped me and a couple of others with similar errors coming from URL and Fetch in particular.

Community
  • 1
  • 1
greensponge
  • 421
  • 4
  • 9
0

The answer, provided by @mgiesa, was to disable Visual Studio TypeScript compilation. The various build tools were all competing and had varying TypeScript configurations. This has become much easier with the Visual Studio releases since the original question.

Jonathan Eckman
  • 2,071
  • 3
  • 23
  • 49