I'm using Visual Studio 2019 and TypeScript 3.9.
I continued working on a React/.NET project when upon creating a few new tsx files Intellisence displayed a few errors, such as:
TS1259: [...] can only be default-imported using the 'esModuleInterop' flag
TS2307: can not find module [...]
The former shows up only in the new files, the latter in the index.d.ts
file which a haven't modified since it worked the last time.
I verified:
- The correct tsconfig file is targeted (the project only contains one).
- I set the tsconfig file's build setting from 'None' to 'Contenct'.
Even after deleting the .vs folder and restarting VS it won't work.
EDIT: "esModuleInterop": true
is also verified.
EDIT: Steps to reproduce:
- Instal VS 2019 and Node.
- Create a new React/.NET Core project in VS2019.
-
- Upgrade the react scripts to the latest with npm upgrade react-scripts --latest
- Remove all eslinting packages with npm remove eslint eslint-config-react-app eslint-plugin-flowtype eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react¹
- Install or upgrade TypeScript
- To install TypeScript use npm install typscript --latest --save-dev
- or if you already have TypeScript installed you can upgrade with npm upgrade TypeScript --latest
- Install the TypeScript definition files with npm install @types/node @types/react @types/react-dom @types/react-router
- Create the following tsconfig file:
"include": [
"src/*"
],
"compilerOptions": {
"target": "es5",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
}
}
- Create a new .tsx file and install and import some packages:
import React, { Component } from 'react';
import * as microsoftTeams from "@microsoft/teams-js";
import { Button } from "@fluentui/react-northstar";
import { AuthenticationContext, adalFetch, withAdalLogin } from 'react-adal';
It may or may not result in an TS2307 error.