Cannot find package '/vercel/path0/apps/nextjs/node_modules/velite/index.js' imported from /vercel/path0/apps/nextjs/next.config.js
unhandledRejection [Error: Cannot find package '/vercel/path0/apps/nextjs/node_modules/velite/index.js' imported from /vercel/path0/apps/nextjs/next.config.js
- [x] Yes, I have velite on my
dependenciesand also tried ondevDependencies - [x] Yes, I have the script under
next.config.mjsas described here: https://velite.js.org/guide/with-nextjs#%F0%9F%8E%8A-start-velite-with-next-js-config-%F0%9F%86%95 - [x] It fails on
import("velite"); - [x] Turborepo setup.
- [x]
"build": "velite && next build"also fails
https://github.com/zce/velite/issues/311#issuecomment-2779093735
@zce Interesting. But I don't use npm-run-all at all. I only followed: velite.js.org/guide/with-nextjs#🎊-start-velite-with-next-js-config-🆕 (Start Velite with Next.js Config 🆕)
I also did 1 or the other for the build script:
Case 1: Only have next.config.mjs (the v.build() code) + without "build": "velite && next build" script; - it did not work.
Case 2: Only have the "build": "velite && next build" script, Without the next.config.mjs (the v.build() code). - it did not work.
The error message is always:
unhandledRejection [Error: Cannot find package '/vercel/path0/apps/nextjs/node_modules/velite/index.js' imported from /vercel/path0/apps/nextjs/next.config.js
Not, .velite/index.js cannot be resolved (The issue you linked).
Will try to figure it out though, it might be a special case since we use Turbo in our codebase.
Actually I might be wrong, I'll read the issue a bit more carefully, sorry.
I have removed everything related to Velite in the next.config.js. I also have velite.config.ts.
I only have this in my package.json:
"build": "npx velite && pnpm next build",
// I also tried
"build": "velite && pnpm next build",
No luck so far.. But the error is new:
[VELITE] Cannot find package 'node_modules/velite/index.js' imported from node_modules/.velite.config.compiled.mjs
Is it possible that esbuild in the https://github.com/zce/velite/blob/main/src/config.ts is just generating a bad import path? Like "velite" turns into "node_modules/velite/index.js" when it saves into .velite.config.compiled.mjs
I think I give up 😢🙏, I think there's something wrong when Velite is used with Turborepo. Weird thing is, it used to work for a while until one of our packages got updated, then even downgrading the package wouldn't fix it. It's so weird.
Hmmm for some reason I can finally deploy when I downgraded the related esbuild version from 0.25.3 to 0.25.1. I definitely feel like the culprit here was using the wrong esbuild version.
But it was super indirect, the packages we upgraded were:
- "@fastify/swagger": "^9.4.2" -> "@fastify/swagger": "^9.5.0"
- [email protected] -> [email protected]
- @tanstack/[email protected] -> @tanstack/[email protected]
I downgraded everything back and it started to work. I think one of the culprits was "tsx" which was directly dependent on esbuild.
Hi @zce. So I managed to find the fix!!!
I had to do pnpm patch. The reason for the bad import was actually because velite's package.json doesn't contain "main": "dist/index.js"
Here were the steps
# 1. Go to the repo where velite is installed
cd apps/nextjs
# 2. Run the patch command for velite
pnpm patch velite
# 3. It should create a folder hoisted in root called `.pnpm-patches/[email protected]`. Edit the package.json in that folder
# to just include
{
...
"main": "dist/index.js",
...
}
# 4. Run the patch commit command
pnpm patch-commit <The absolute path to .pnpm-patches/[email protected]>
# 5. It should create a `patches/velite.patch` file in root.
# Just commit and push to Vercel, and it will be fixed.
I'm gonna try making a PR for this. (I'll use my personal account, this is my work account lol)
fixed by https://github.com/zce/velite/pull/320