Search code examples
typescriptwebpackwebpack-4tsconfig

Webpack "Cannot find module" for "module": "esnext"


I have a webpack project with this in my "main.ts" module:

import {Elm} from "./MainModule";

it fails with:

TS2307: Cannot find module './MainModule'.

but when I switch my "tsconfig.json" from "module": "esnext" to "module": "commonjs", it works.

However, I need "esnext" in order to have code splitting.

Thoughts?


Solution

  • I had the same issue, adding "moduleResolution": "node", to tsconfig.json seems to have fixed it.

    More info on it here: https://www.typescriptlang.org/docs/handbook/module-resolution.html