opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
23 stars 0 forks source link

[SvelteKit] Dev Error: Failed to load url [...] #112

Closed xKesvaL closed 1 month ago

xKesvaL commented 2 months ago

What happened

Hi! I'm getting this error using paraglide-sveltekit 0.6.15 with paraglide 1.8.0. This did not happen before, when I was using a very much older version of the package which still was named paraglide-js-adapter-sveltekit

[vite] Error when evaluating SSR module /src/hooks.server.ts: failed to import "/src/lib/utils/i18n.ts"
Error: Failed to load url /src/paraglide/messages/index/about_hero_title.js (resolved id: /src/paraglide/messages/index/about_hero_title.js) in /home/kesval/Coding/@kesval/kesval.com/src/paraglide/messages.js. Does the file exist?
    at loadAndTransform (file:///home/kesval/Coding/@kesval/kesval.com/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:53884:21)
    at async instantiateModule (file:///home/kesval/Coding/@kesval/kesval.com/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:54954:10) {
  code: 'ERR_LOAD_URL'
}

Versions and troubleshooting

Reproduction (repo)

This is the repo. To reproduce, just go on the refactor-inlang branch, install packages and run the dev script. When getting on the website, the website simply crashes and gives the error below.

However, when you try to run the build script it works fine, wether it is on my machine or on vercel.

LorisSigrist commented 2 months ago

There was a bugfix for how paraglide's build output is handled internally in vite. This was supposed to be non-breaking but your issue makes it seem like there is a bug.

Revert the SvelteKit adapter to 0.6.14 for now while I troubleshoot this

Thanks for the Reproduction Repo!

LorisSigrist commented 1 month ago

Seems to be a linux-only issue, I can't reproduce this.

For now I'll fix this by only applying the build transformations when actually building & turning them off during development. Build seems to work fine.

canseyran commented 1 month ago

You can try this workaround until the bug is fixed, to compile the messages using the cli on vite serve and use the plugin only on build.

...
import { watch } from 'vite-plugin-watch';

export default defineConfig({
  plugins: [
    {
      ...watch({
        pattern: './src/lib/features/i18n/translations/*/*.json',
        command: 'npm run i18n:compile',
        silent: true
      }),
      apply: 'serve'
    },
    {
      ...paraglide({
        project: './project.inlang',
        outdir: './src/lib/paraglide'
      }),
      apply: 'build'
    },
    sveltekit(),
  ...
});
// package.json
...
"i18n:compile": "paraglide-js compile --project ./project.inlang --outdir ./src/lib/paraglide",
xKesvaL commented 1 month ago

Thanks for the quick reply as always @LorisSigrist , reverting to 0.6.14 did in fact work for me, so I'll use that for now. Also thanks anyways @canseyran for your workaround :)

LorisSigrist commented 1 month ago

Fix should be out later today, deployment is being blocked by another issue