Closed mgreystone closed 1 year ago
Same here.
I found a workaround for now, which is editing the resolve.alias
option in the webpack config from:
svelte: path.resolve('node_modules', 'svelte')
to:
svelte: path.resolve('node_modules', 'svelte/src/runtime')
I don't think this should be the solution, tho.
This takes advantage of the file structure of the Svelte package, rather than the exports
field in its package.json
. This is brittle.
Could anyone shed some light on why that resolve.alias
is needed anyway? I've removed it and it continues to work in the webpack template. I suspect this is a leftover from some ancient webpack version which is no longer needed / causing harm now.
Edit: The explanation in the svelte-loader
sheds some light on this. I think this is not needed in the vast majority of cases, so it's probably best to comment it out (and people can comment it in if they need to)
The readme and webpack-template have been updated.
Thanks!
In my case, it would fail to compile even without doing npm link
to another package.
For some reason, if you use a Svelte component library package, there's a chance that Webpack will compile your app and the component library separately. When that happens, you have two runtimes in the same app, and things fall apart quickly.
It is really hard to debug, cause you can't see those two conflicting versions unless you're really looking for it.
I think that the option could be left there uncommented because it creates way more confusion not having it in case you need it, than having it but being somewhat linked to the package structure.
Maybe someone could come up with a better and less brittle solution.
I see, I'll add it back uncommented then. I don't think there's a better solution to this if webpack behaves this weirdly - we'll just have to make sure the internal path doesn't change between major versions of Svelte (which it shouldn't, anyway).
I see, I'll add it back uncommented then. I don't think there's a better solution to this if webpack behaves this weirdly - we'll just have to make sure the internal path doesn't change between major versions of Svelte (which it shouldn't, anyway).
Even if the internal structure changes, now you know that it could have this impact and you could communicate it.
Furthermore, I think that googling one submodule not resolving in webpack after an update could be more insightful than googling for this weird problem that could happen for many reasons, one of which is that resolve.alias
thing.
Neither the documentation nor the example template do not work with svelte 4.
npm install svelte@latest
npm run dev
Webpack fails to build with errors. Internal svelte modules do not resolve.
Example: https://github.com/mgreystone/template-webpack