Moon Rat
Moon Rat

Reputation: 25

SvelteKit + Vercel Serverless Function Crash : [ERR_INVALID_MODULE_SPECIFIER]

I would sure be glad if someone could help me here...

  1. My website is built using SvelteKit (v2), with Prismic as a CMS, and deployed via Vercel.
  2. Everything runs smoothly locally, with no error, in the dev environment but also in the build preview.
  3. Online, when I'm trying to access dynamic routes (e.g. /about works fine because it's static, but not the localized version /fr-ca/about) I get a server side function crash.

Here's what info I got from Vercel log. From what I understand it seems to be some kind of parsing error? Something to do with backslashes being added/not being removed somewhere (see the %5C in the error message)?

TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "/var/task/..%5C..%5C..%5Cwebsite%5C.svelte-kit%5Cvercel-tmp%5Cindex.js" 
must not include encoded "/" or "\" characters imported from /opt/rust/nodejs.js
    at finalizeResolution (node:internal/modules/esm/resolve:243:11)
    at moduleResolve (node:internal/modules/esm/resolve:937:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:1161:14)
    at defaultResolve (node:internal/modules/esm/resolve:1204:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
    at defaultImportModuleDynamically (node:internal/modules/esm/utils:194:31)
    at importModuleDynamicallyCallback (node:internal/modules/esm/utils:216:12) {
  code: 'ERR_INVALID_MODULE_SPECIFIER'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.

I already have spent a day trying to figure this out, any help would be welcome. Here's what I have tried so far:

  1. Remove .vercel and add it to .gitignore (as suggested in this thread)
  2. Update modules through npm update
  3. Change the adapter, try to run from edge to see if it would help (it did not)

Upvotes: 0

Views: 144

Answers (1)

Moon Rat
Moon Rat

Reputation: 25

So after fiddling with this for another day I have found the issue.

The backslashes were coming from the the handler: '\\..\\..\\.svelte-kit\\vercel-tmp\\index.js in vc-config.json. All of this is because of the default fn function created in the .vercel output build folder. Removing it and placing it in .gitignore finally did the trick, I don't know what I did before that wasn't working.

Upvotes: 1

Related Questions