Cannot find package knex on production build of nuxt server (api routes)
Forwarded from downstream issue:
|
Environment
- Operating System: Windows_NT
- Node Version: v18.16.0
- Nuxt Version: 3.6.5
- Nitro Version: 2.5.2
- Package Manager: [email protected]
- Builder: vite
- User Config: devtools, modules, content, experimental
- Runtime Modules: @nuxtjs/[email protected], @nuxt/[email protected], @nuxtjs/[email protected]
- Build Modules: -
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:
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:
I don't use TypeScript but JavaScript in ~/server.
Additional context
No response
Logs
No response
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: -
Уже больше года проблема не сортируется. Nitro мы помираем?
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
oracledband that "externals are not allowed" - I forked knex and removed the other dialects throughout the project and now getting an issue with
wrangler deployto 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 devworks - I can connect to the db. Runningnuxt build; wrangler --cwd .output deployerrors.
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 any update on this?