web icon indicating copy to clipboard operation
web copied to clipboard

The module @web/dev-server-esbuild does not seem to observe the `paths` definition in tsconfig.json

Open doberkofler opened this issue 1 year ago • 2 comments

I'm currently testing the Moden web test Runner and trying to use @web/dev-server-esbuild to build my tests written in TypeScript. Unfortunately it seems as if the import alias defined in @web/dev-server-esbuild are not properly processed.

{
	"compilerOptions": {
		"target": "ESNext",
		"module": "ESNext",
		"moduleResolution": "node",
		"strict": true,
		"esModuleInterop": true,
		"skipLibCheck": true,
		"allowSyntheticDefaultImports": true,
		"types": ["@playwright/test", "mocha", "chai"],
		"paths": {
			"@alias_root/*": ["./*"]
		}
	},
	"include": ["**/*.ts"]
}

A quick look into the source code of @web/dev-server-esbuild suggests that the function resolveImport in EsbuildPlugin.ts skips to entirely process all files that does not start with . to only handle relative imports, but does this before having resolved the alias and therefore missing the import using an alias.

    if (!source.endsWith('.js') || !source.startsWith('.')) {
      // only handle relative imports
      return;
    }

doberkofler avatar Oct 27 '24 10:10 doberkofler

Any update on this? I think I'm looking into the same issue, as I'm seeing the following error when running the tests: Error while transforming xxx.spec.ts: Could not resolve import "@shared... where @shared is defined as an alias in tsconfig.

segesjesl avatar Sep 10 '25 08:09 segesjesl

I too am facing this issue with path aliases

KonnorRogers avatar Dec 05 '25 15:12 KonnorRogers