Visual studio 2019 Cannot use imports, exports, or module augmentations when '--module' is 'none'

Viewed 640

After I upgraded my project from Angular 9 to Angular 10 the project is showing many errors that I can't resolve like the following

(TS) Cannot find module '@angular/core'.
(TS) Cannot find module '@angular/forms'.
(TS) Cannot use imports, exports, or module augmentations when '--module' is 'none'.
(TS) Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
TS6053 File 'ClientApp/node_modules/-/dist/index.d.ts' not found

The error messages are only shown in visual studio 2019. when I try the application in visual studio code it is working fine.

I have tried many solutions like adding
<TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators> <TypeScriptEmitDecoratorMetadata>True</TypeScriptEmitDecoratorMetadata>

or adding
"baseUrl": "src"
to the tsconfig.json

non of them worked. Did anyone have the same problem?

1 Answers

That is an issue with Visual Studio 2019 not being able to process new "solution-style" tsconfig files.

You may read about the changes that came with Angular 10 CLI upgrade:

https://angular.io/guide/migration-solution-style-tsconfig

The easiest workaround for you in order to get things to work properly in Visual Studio 2019 is to change your tsconfig.json file to work without "solution-style" configuration mode like this:

{
  "extends": "./tsconfig.app.json"
  //"files": [],
  //"references": [
  //  {
  //    "path": "./tsconfig.app.json"
  //  },
  //  {
  //    "path": "./tsconfig.spec.json"
  //  }
  //]
}

This is a known issue and Visual Studio team is currently working on it to support this new style of TypeScript configuration files.

Related