error TS1259: Module '"./node_modules/@types/express/index"' can only be default-imported using the 'esModuleInterop' flag error TS1259: Module '"./node_modules/@types/express/index"' can only be default-imported using the 'esModuleInterop' flag typescript typescript

error TS1259: Module '"./node_modules/@types/express/index"' can only be default-imported using the 'esModuleInterop' flag


In my case, I was facing this error for react. I fixed it by changing my import style from

import React from 'react';

to

import * as React from 'react';


As the error states, you need the set

"esModuleInterop": true,

in your tsconfig.json file. This allows default imports from modules with no default export.


According to your GitHub repo, you have the following structure (some files/directories have been omitted):

Bad:

  • server
    • src
      • tsconfig.json
  • server2
    • src
    • tsconfig.json

You will need to move /server/src/tsconfig.json to /server/tsconfig.json - please note that you will need to MOVE, not COPY the tsconfig file.

Good:

  • server
    • src
    • tsconfig.json
  • server2
    • src
    • tsconfig.json