platforms icon indicating copy to clipboard operation
platforms copied to clipboard

Edge function Error : ERR_MODULE_NOT_FOUND on an installed module

Open Britnell opened this issue 1 year ago • 1 comments

Hey team, I have an error I'm struggling to fix. I find similar MODULE_NOT_FOUNDS, but those seemed different.

  • I am deploying my astro site on vercel
  • Britnell/pushbullet
  • turso hosted sqlite db
  • building & running locally fine
  • e.g. homepage is fine
  • error happens on login api route , server crashes with :
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@libsql/client' imported from /var/task/.vercel/output/_functions/chunks/pages/app_m16mYN8C.mjs
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:965:9)
    at moduleResolve (node:internal/modules/esm/resolve:1022:20)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:876:12)
    at defaultResolve (node:internal/modules/esm/resolve:1242:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:403:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:372:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:39)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'

I am using libsql/client to connect to turso db the endpoint is loading sql client :

import { createClient } from "@libsql/client/web";
export const turso = createClient({
  url: import.meta.env.TURSO_URL,
  authToken: import.meta.env.TURSO_TOKEN,
});

So it is failing to import an installed package. the build & install run fine, this works fine locally, I was using pnpm, so tried out with npm i too, but still had the same issue.

I was using bcrypt package which had problems running on edge, which i replaced with bcryptjs but libsql is a lightweight client suggested by turso, i feel like this should be able to work. Do you have any other debugging tips I can try?

Britnell avatar Feb 03 '24 14:02 Britnell

In fact i just deployed the same project to Netlify and it works fine, so this must be the astro/vercel adapter. I don't know if you have access to my vercel deploy?

Britnell avatar Feb 03 '24 14:02 Britnell