sveltejs / svelte-loader

Webpack loader for svelte components.
MIT License
594 stars 73 forks source link

Issue with .svelte.js files and Svelte 5 #238

Open andersekdahl opened 2 months ago

andersekdahl commented 2 months ago

This might not be a problem in svelte-loader but rather in the svelte compiler, but the issue shows itself in svelte-loader.

When I created a xxx.svelte.js file which got included in my webpack build I started getting a wierd error about Error: callback(): The callback was already called.. But that error turned out to not be the real error, it was just that an error was thrown here:

https://github.com/sveltejs/svelte-loader/blob/f2a7bc1364939ba2efc51f4400e0a85360f0a123/index.js#L97

Which triggered this line: https://github.com/sveltejs/svelte-loader/blob/f2a7bc1364939ba2efc51f4400e0a85360f0a123/index.js#L101

And since the error occured inside the callback the error became callback(): The callback was already called.

The real error was:

TypeError: Cannot read properties of null (reading 'startsWith')
    at contextifySourceUrl (/home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/webpack/lib/NormalModule.js:124:13)
    at /home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/webpack/lib/NormalModule.js:154:3
    at Array.map (<anonymous>)
    at contextifySourceMap (/home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/webpack/lib/NormalModule.js:153:39)
    at NormalModule.createSource (/home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/webpack/lib/NormalModule.js:799:5)
    at processResult (/home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/webpack/lib/NormalModule.js:870:24)
    at /home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/webpack/lib/NormalModule.js:964:5
    at /home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/loader-runner/lib/LoaderRunner.js:407:3
    at iterateNormalLoaders (/home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/loader-runner/lib/LoaderRunner.js:233:10)
    at iterateNormalLoaders (/home/anders.ekdahl/source/stickerapp/olympus/atlas/node_modules/loader-runner/lib/LoaderRunner.js:240:10)

I don't know what the cause is here, but if I stop passing js.map to callback() the error goes away so I guess it's something with Svelte 5s sourcemaps for .svelte.js files that causes it.

This is the contents of js.map when the error happens:

{
  version: 3,
  names: [],
  sources: [ null ],
  sourcesContent: [ null ],
  mappings: ';;;aAAa,OAAO;uBACG,IAAI;;KAAvB,SAAS;;;;KAAT,SAAS;;;;6BACgB,KAAK;;KAA9B,eAAe;;;;KAAf,eAAe;;;;6BACU,KAAK;;KAA9B,eAAe;;;;KAAf,eAAe;;;;CACf,eAAe;;;KACf,4BAA4B;;;;KAA5B,4BAA4B;;;;;;KAC5B,6BAA6B;;;;KAA7B,6BAA6B;;;;;;KAC7B,gBAAgB;;;;KAAhB,gBAAgB;;;;;;KAChB,qBAAqB;;;;KAArB,qBAAqB;;;;;;KACrB,yBAAyB;;;;KAAzB,yBAAyB;;;;;;KACzB,6BAA6B;;;;KAA7B,6BAA6B;;;;;;KAC7B,oCAAoC;;;;KAApC,oCAAoC;;;;;SAExB,IAAI,CAAC,qBAAqB,CAAC,MAAM,IACrC,IAAI,CAAC,yBAAyB,CAAC,MAAM,IACrC,IAAI,CAAC,6BAA6B,CAAC,MAAM,IACzC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM;;;KAJrE,iBAAiB;;;;;QAYP,WAAW;;aACN,eAAe,IAAI,IAAI,CAAC,gBAAgB;SACzC,MAAM;OACR,UAAU,GAAG,CAAC;;cACP,IAAI,IAAI,eAAe,CAAC,KAAK;SAC/B,MAAM,CAAC,IAAI,CAAC,gBAAgB;KAC7B,MAAM,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC;;;IAErC,MAAM,CAAC,IAAI,CAAC,gBAAgB;;QACxB,MAAM,CAAC,IAAI,CAAC,gBAAgB,IAAI,UAAU;KAC1C,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,gBAAgB;;;;GAGjD,WAAW,CAAC,eAAe,CAAC,EAAE,IAAI,UAAU;;;SAEzC,WAAW;;;KAhBtB,0BAA0B;;;;;QAsBhB,MAAM;;aACD,cAAc,IAAI,IAAI,CAAC,eAAe;SACv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