Cannot find package knex on production build of nuxt server (api routes)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
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: npm@9.5.1
- Builder: vite
- User Config: devtools, modules, content, experimental
- Runtime Modules: @nuxtjs/tailwindcss@6.8.0, @nuxt/content@2.7.2, @nuxtjs/eslint-module@4.1.0
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and compare npm run dev with npm run build followed by npm run preview, focusing on the API under ~/server/api and the generated ./output/server/node_modules. Check the forwarded Nuxt issue for current context; done means the production server can load knex and serve the SQLite-backed API without the package error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, nuxtjs, sqlite, vite
- Domain
- api, backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100