reactjsecmascript-6commonjsreact-typescript

npm run build fails to compile transpiled App.js file. Suspected ES6 and commonJS mismatch


While compiling the transpiled ES6 JS files from TS (React), I ran into this error:

Cannot get final name for export '__esModule' of ./src/App.js while generating the root export '__esModule' (used name: '__esModule')

This is my tsconfig.json

"compilerOptions": {
    "jsx": "react",
    "target": "es6", 
    "lib": ["dom", "esnext"], 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true, 
    "forceConsistentCasingInFileNames": true,
    "strict": true, 
    "skipLibCheck": true
}

I was not able to find a relevant explanation online after hours of scouring. Any help is appreciated.


Solution

  • In your tsconfig.json file, change the "module" to "ESNext" like this:

    {
      "compilerOptions": {
        "module": "ESNext",
      }
    }