madge icon indicating copy to clipboard operation
madge copied to clipboard

`tsconfig.json` 's `compilerOptions.path` and `extends` doesn't seem to work in sveltekit projects

Open aubelsb2 opened this issue 2 years ago • 3 comments

I'm not sure if this issue has already been logged (I did a search but wasn't able to determine if it was related.) However when working with a sveltekit deployment I had to global search and replace all imports to relative imports rather than using the "path alias" that's configured out the box.

Perhaps this is to do with Sveltekit's use of including a generated tsconfig file (that is also often in the .gitingore file as it's generated.)

However the base tsconfig.json file looks like this:

{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"allowJs": true,
		"checkJs": true,
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"resolveJsonModule": true,
		"skipLibCheck": true,
		"sourceMap": true,
		"strict": true
	}
	// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
	//
	// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
	// from the referenced tsconfig.json - TypeScript does not merge them in
}

URL seems relevant. It requires the "extends": "./.svelte-kit/tsconfig.json", in order to work and that's because ./.svelte-kit/tsconfig.json contains:

{
	"compilerOptions": {
		"paths": {
			"$lib": [
				"../src/lib"
			],
			"$lib/*": [
				"../src/lib/*"
			]
		},
		"rootDirs": [
			"..",
			"./types"
		],

This setup seems to cause a lot of tools issues. Including my IDE -_-.

I wasn't able to find in the documentation or by doing a quick source and issue search if this issue has been logged, resolved or documented so I wrote it here.

Any sample sveltekit project should demonstrate the same issue as the aliases are used quite heavily, although some people replicate them in the root tsconfig.json file. See:

https://github.com/tsukhu/sveltekit-demo/blob/92ba565bc2c27ed610e907bf00f5264e773d0e67/tsconfig.json#L12-L21

(Just one I found after a quick google nothing significant about this particular example.)

aubelsb2 avatar Feb 08 '23 23:02 aubelsb2

I updated dependency-tree and detective-typescript packages manually, and seems it working.

Delagen avatar Jan 31 '24 05:01 Delagen

the same problem. Are there any details of the upgrade? @Delagen

nbili avatar Mar 04 '24 18:03 nbili

We discussed it already in !399

Delagen avatar Mar 04 '24 19:03 Delagen