moduleResolution: bundler causing module resolution errors with certain modules in VSCode

1k Views Asked by At

I have moduleResolution set to bundler - my tsconfig looks like this:

{
    "extends": "@vue/tsconfig/tsconfig.dom.json",
    "compilerOptions": {
        "types": ["vite/client"]
    }
}

(@vue/tsconfig/tsconfig.dom.json sets moduleResolution to bundler)

When I try to import the broadcast-channel package, VS Code gives me a TS 2307 error.

Here are the relevant parts of broadcast-channel's package.json:

{
  "exports": {
    ".": {
      "node": {
        "types": "./types/index.d.ts",
        "import": "./dist/esnode/index.js",
        "default": "./dist/es5node/index.js"
      },
      "browser": {
        "types": "./types/index.d.ts",
        "import": "./dist/esbrowser/index.js",
        "default": "./dist/lib/index.es5.js"
      }
    },
    "./package.json": "./package.json"
  },
  "main": "./dist/es5node/index.js",
  "module": "./dist/esnode/index.js",
  "browser": "./dist/lib/index.es5.js",
  "sideEffects": false,
  "types": "./types/index.d.ts"
}

When I set moduleResolution to node manually in my tsconfig, the error goes away. Why does it even occur in the first place? Importing other modules like idb works.


I'm using Typescript 5.1.6 with Volar 1.8.8 running in takeover mode. VS Code 1.80.2.

0

There are 0 best solutions below