Describe the bug
Yesterday with v101.0.0 I finished migrating my Svelte components library to TS with almost no / no severe (correctly compiling) TS-errors. Today with v101.1.1 (checked: starting with v101.1.0) I get a bunch of ts(2440) (+ a lot of resulting) errors: Import declaration conflicts with local declaration of 'Foo', while everything is still compiling / building correctly as with v101.0.0. I'm not sure though if this is a bug or a feature which was not functioning correctly in v101.0.0.
Running svelte-check reports same errors.
To Reproduce
I'm going to describe as simple as possible how I'm building the mentioned library.
It's a library of Svelte components 'target_lib' wrapping modules of library 'source_lib'. Svelte wrapper-components and their corresponding modules from 'source_lib' have identical names:
// Svelte wrapper-component 'Foo.svelte'
<script lang="typescript">
import { Foo } from 'source_lib'
</script>
// 'target_lib.ts'
export { default as Foo } from './components/Foo.svelte'
export * from 'source_lib'
When building 'target_lib' Rollup is renaming duplicates like this in the 'target_lib.mjs':
Foo from 'source_lib' keep name Foo
Svelte wrapper-Foo-components are being renamed to Foo_1 (+ _1)
This might seem like bad practice but is exactly how I want it to be, it works as intended: Svelte 'target_lib'-'Foo' components override (and utilize) corresponding 'source_lib'-'Foo' components when e.g.
//Test.svelte
<script>
import { Foo } from 'target_lib'
</script>
<Foo />
Expected behavior
I don't know what to expect, because I don't know if ts(2440) errors are a bug or a feature. Rollup builds o.k. as expected / as before despite the "new" errors.
Actually it feels like correct behavior that these conflicts are being reported, but on the other hand it makes Rollup's ability to manage such cases obsolete and then it feels kind of wrong again. I would just like to get a clear response if this is intended / correct behavior, then I would know if I have to think of another solution / fix / find workaround or wait for an update. Thanks!
System (please complete the following information):
"devDependencies": {
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-node-resolve": "^8.1.0",
"@rollup/plugin-typescript": "^5.0.1",
"prettier": "^2.0.5",
"rollup": "^2.21.0",
"rollup-plugin-svelte": "^5.2.3",
"rollup-plugin-terser": "^6.1.0",
"svelte": "^3.24.0",
"svelte-check": "^0.1.47",
"svelte-preprocess": "^4.0.6",
"tslib": "^2.0.0",
"typescript": "^3.9.6"
},
```json
//tsconfig.json
{
"compilerOptions": {
"target": "es2017",
"strict": false,
"moduleResolution": "node",
"allowJs": false,
"sourceMap": true,
"lib": [
"es2017", "DOM"
],
"types": [
"svelte"
],
"baseUrl": "."
},
"include": [
"src/*/"
],
"exclude": [
"node_modules/", "dist/"
]
}
```javascript
//rollup.config.js
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import {terser} from 'rollup-plugin-terser';
import pkg from './package.json';
import preprocess from 'svelte-preprocess'
...
const production = !process.env.ROLLUP_WATCH;
export default {
input: 'src/target_lib.ts',
treeshake: { moduleSideEffects: false },
output: [
{ file: pkg.module, 'format': 'es', sourcemap: true },
{ file: pkg.main, 'format': 'umd', name, sourcemap: true },
],
plugins: [
svelte({
preprocess: preprocess({
typescript: {
transpileOnly: true,
}
})
}),
resolve({
browser: true,
dedupe: ['svelte']
}),
...
]
};
Thanks!
This is a result of a change introduced in #285 , there we changed the transformed tsx output to have named default exports, which are the same as the file. Because of this ts will complain in your Foo.svelte that there are two definitions of Foo now.
As a workaround you can do
Foo.svelte:
<script lang="typescript">
import { Foo as Foo_ } from './sourcelib';
</script>
This is definitely something we did not consider, maybe we should postfix the converted Components with something that is very unlikely to occur in user's code. Something like export default class Foo_SvelteComponent.
Great! Thank you! ✊