[import/no-duplicates] Autofix merges imports incorrectly - single index.d.ts but multiple modules
Working on a Svelte project. For a majority of their packages, they have a single index.d.ts that is used but the d.ts file uses modules for namespacing.
Subset of the package.json exports
"./animate": {
"types": "./types/index.d.ts",
"default": "./src/runtime/animate/index.js"
},
"./easing": {
"types": "./types/index.d.ts",
"default": "./src/runtime/easing/index.js"
},
so for the above fragment I have an imports that looks like this
import { quadOut } from 'svelte/easing'
import { crossfade } from 'svelte/transition'
This yields the following warning:
warning '.../node_modules/.pnpm/[email protected]/node_modules/svelte/types/index.d.ts' imported multiple times import/no-duplicates
but auto fix changes this to the following - which is not correct and doesn't work from a code perspective
import { quadOut, crossfade } from 'svelte'
Trying to determine if there is any way to keep this rule but allow for exception to the rules.
Thanks in advance for any help / guidance.
Are you using eslint-import-resolver-typescript? Please share your config if that doesn't fix it.
Thanks for the quick reply. I am using eslint-import-resolver-typescript. If it helps I created a sample app that uses the standard create svelte app skeleton project.
https://github.com/mpellegrini/eslint-import-plugin-no-duplicates-issue
config being used is here - https://github.com/mpellegrini/eslint-import-plugin-no-duplicates-issue/blob/main/.eslintrc.cjs
The specific file that is exhibiting this behavior is here https://github.com/mpellegrini/eslint-import-plugin-no-duplicates-issue/blob/main/src/routes/%2Bpage.svelte#L2
I have already added the eslint disable on one of the imports that is auto fixing incorrectly.
For other types of imports it is working for me, bot collapsing and keeping things separate as expected. Just specifically with these imports from Svelte.
If there is anything else I can provide please let me know.
I'm having the same issue.
Compilation breaks because of this:
// The following:
import { format, Locale } from 'date-fns';
import { enUS } from 'date-fns/locale';
// is auto-fixed as:
import { enUS, format, Locale } from 'date-fns';
// which results in the following error:
Module '"date-fns"' has no exported member 'enUS'
I'm using [email protected], [email protected] and [email protected]
Here's an even more minimal reproduction. You don't need to actually use svelte to reproduce, just import it.
package.json
{
"dependencies": {
"eslint": "^9.16.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import": "^2.31.0",
"svelte": "^5.9.1"
}
}
index.mjs
import { quadOut } from 'svelte/easing'
import { crossfade } from 'svelte/transition'
eslint.config.mjs
import importPlugin from 'eslint-plugin-import';
export default [
importPlugin.flatConfigs.recommended,
{
settings: {
'import/resolver': {
typescript: {
}
}
}
}
];
I couldn't reproduce with date-fns.
Duplicate of #1479