monorepo: [bug] sveltekit vercel adapter does not bundle paraglide, leading to unresolvable imports

Problem

The SvelteKit Vercel adapter does not bundle paraglide imports.

  1. The imports in the compiled output reference the node modules which don’t exist in the vercel edge runtime. Every other import is referencing build output (“…/chunk.js”)
  2. The directory structure of the build output does not include node_modules which likely leads to this problem. The paraglide import can’t be resolved.

CleanShot 2023-10-18 at 10 18 40@2x

Expected behavior

The bundler processes the paraglide imports instead of leaving them as is.

-import { availableLanguageTags, languageTag, setLanguageTag } from "@inlang/paraglide-js/website";
-import * as m from "@inlang/paraglide-js/website/messages";
+import { a, b, c, messageas } from "../chunk-2ss.js";

Reproduction

TODO

Other information

I suspect the package.exports might play a role here. SvelteKit doesn’t use the TypeScript compiler option moduleResolution: Node16 or Bundler yet by default. It might be that the Vercel adapter ignores export maps altogether. A reproduction could be a mock package with exports fields and see how the Vercel adapter behaves.

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 16 (13 by maintainers)

Most upvoted comments

🎉🎈 @rishi-raj-jain has been awarded $200! 🎈🎊

TLDR

The main change is

ssr: {
     noExternal: ['@inlang/paraglide-js']
}

Explanation in detail

As the compiled-output folder is already transpiled, using noExternal with vite becomes necessary to be used so that is not left out while bundling.

More specifically, the issue was due to exclusion of the file messages.js in the node_modules of the vercel output while treeshaking, while runtime.js was included because as being the default export from the package.