nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Cannot find package knex on production build of nuxt server (api routes)

Open issue-up[bot] opened this issue 2 years ago • 4 comments

   Forwarded from downstream issue:

  • https://github.com/nuxt/nuxt/issues/22373 by @bvqbao

Environment



Reproduction

https://github.com/bvqbao/nuxt3-module-notfound

Describe the bug

I have created some API in ~/server/api. The API use knex package to access to an SQLite DB. In dev mode (npm run dev), the API work as expected: image

However, when I build the server for production (npm run build) and run the server (npm run preview), the server returns an error about "Cannot find package ..." knex, altho it is present in ./output/server/node_modules: image

I don't use TypeScript but JavaScript in ~/server.

Additional context

No response

Logs

No response

issue-up[bot] avatar Jul 28 '23 10:07 issue-up[bot]

Hi, same problem here (I do use TypeScript in ~/server). Nuxt server project with knex fails in preview/production mode.

Operating System: Windows_NT Node Version: v22.6.0 Nuxt Version: 3.12.4 Nitro Version: 2.9.7 Package Manager: [email protected] Builder: vite User Config: devtools, compatibilityVersion : 4 Runtime Modules: - Build Modules: -

Zebnastien avatar Aug 15 '24 15:08 Zebnastien

Уже больше года проблема не сортируется. Nitro мы помираем?

Predprinimatel89 avatar Oct 28 '24 09:10 Predprinimatel89

Similarly, I'm hitting a blocker on a new project using Nuxt 4, Nitro 2.12.4 where knex throws lots of errors:

  • my project uses sqlite
  • was getting errors that Nitro couldn't find oracledb and that "externals are not allowed"
  • I forked knex and removed the other dialects throughout the project and now getting an issue with wrangler deploy to a Cloudflare Worker that "[ERROR] A request to the Cloudflare API (/accounts/redacted/workers/scripts/project-name/versions) failed." uncaught typeerror: <random minimized name> is not a function.
  • Running nuxt dev works - I can connect to the db. Running nuxt build; wrangler --cwd .output deploy errors.

In a non-nitro project (built off of https://github.com/sutandojs/sutando-examples/tree/main/typescript/rest-hono-cf-d1), the deploy to CF workers (using the fresly-minted v2.0.1 of knex-cloudflare-d1) works fine in both dev and deploy.

I believe the issue is with how Nitro is compiling knex. I'm going to continue looking into this.

pnwmatt avatar Jul 25 '25 19:07 pnwmatt

@pnwmatt any update on this?

jjjrmy avatar Sep 16 '25 02:09 jjjrmy