aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.28k stars 45 forks source link

Cannot find module tsconfig-paths\lib\tsconfig-loader in ESM mode #27

Closed gunters63 closed 3 years ago

gunters63 commented 3 years ago

I want to switch to ESM mode ("type": "module"). vite-tsconfig-paths gives me above error. It seems ESM should be supported because I can see

  "exports": {
    "import": "./dist/index.mjs",
    "require": "./dist/index.js"
  },

in the package.json of vite-tsconfig-paths so it should be a hybrid module.

When I look into dist/index.mjs there is the following include:

import {
  loadTsconfig,
  walkForTsConfig
} from "tsconfig-paths/lib/tsconfig-loader";

which fails

gunters63 commented 3 years ago

Strangely it works when I patch index.mjs like this:

import {
  loadTsconfig,
  walkForTsConfig
} from "tsconfig-paths/lib/tsconfig-loader.js";

I have no idea why he cannot resolve the module without the explicit extension

aleclarson commented 3 years ago

Whoops. The explicit .js extension was included in #24, but I naïvely removed it without asking why it was added. 😅

This page describes why it's necessary (see the last sentence below):

image
aleclarson commented 3 years ago

Released in v3.3.13