[🐞] Vercel build fails with mongodb - Cannot bundle Node.js built-in "stream"
Which component is affected?
Qwik Rollup / Vite plugin
Describe the bug
I'm trying to use Atlas (using the mongodb npm package) with my vercel qwik.js app but am getting this error on build in vercel, so I think vercel can handle using the MongoDB package. It works fine locally.
[commonjs] Cannot bundle Node.js built-in "stream" imported from "node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/cursor/abstract_cursor.js". Consider disabling ssr.noExternal or remove the built-in dependency.
I have enabled the Vercel-Atlas integration and have also managed to deploy the example NextJs/Atlas demo (https://github.com/duncan1a/vercel-demo) on vercel. I've used the same MongoDB package version in my readitsideways qwik repo.
https://github.com/duncan1a/readitsideways/tree/blog
I don't know where else to look to fix the issue
[commonjs] Cannot bundle Node.js built-in "stream" imported from "node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/cursor/abstract_cursor.js". Consider disabling ssr.noExternal or remove the built-in dependency.
--
16:35:13.556 | file: /vercel/path0/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/cursor/change_stream_cursor.js
16:35:13.561 | error during build:
16:35:13.562 | RollupError: Cannot bundle Node.js built-in "stream" imported from "node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/cursor/abstract_cursor.js". Consider disabling ssr.noExternal or remove the built-in dependency.
16:35:13.562 | at error (file:///vercel/path0/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
16:35:13.562 | at Object.error (file:///vercel/path0/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18454:20)
16:35:13.562 | at Object.resolveId (file:///vercel/path0/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:28998:34)
16:35:13.562 | at Object.handler (file:///vercel/path0/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67017:19)
16:35:13.562 | at file:///vercel/path0/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18639:40
16:35:13.562 | at async PluginDriver.hookFirstAndGetPlugin (file:///vercel/path0/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18539:28)
16:35:13.562 | at async resolveId (file:///vercel/path0/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:17208:26)
16:35:13.562 | at async ModuleLoader.resolveId (file:///vercel/path0/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:17622:15)
16:35:13.562 | at async file:///vercel/path0/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:8338:16
16:35:13.562 | at async Promise.all (index 0)
16:35:13.597 | ELIFECYCLE Command failed with exit code 1.
Reproduction
https://github.com/duncan1a/readitsideways/tree/blog
Steps to reproduce
Deploy to Vercel
System Info
System:
OS: macOS 14.2.1
CPU: (12) arm64 Apple M3 Pro
Memory: 2.36 GB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v18.18.2/bin/yarn
npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
pnpm: 8.10.4 - ~/.nvm/versions/node/v18.18.2/bin/pnpm
Browsers:
Chrome: 120.0.6099.216
Edge: 120.0.2210.133
Safari: 17.2.1
npmPackages:
@builder.io/qwik: ^1.3.5 => 1.3.5
@builder.io/qwik-auth: 0.1.1 => 0.1.1
@builder.io/qwik-city: ^1.3.1 => 1.3.1
undici: ^5.26.0 => 5.28.2
vite: ^5.0.6 => 5.0.10
### Additional Information
The mongo integration works fine locally, but it fails the build in vercel
Isn't this a duplicate of #5714
I'm not sure. That looked to me like he didn't need SSR. I do though, and vercel can handle the mongodb package, just not with the qwik config it seems
@duncan1a I propose you experiment with how to build for Vercel, and share your findings here. Vercel has a plugin for vite it seems. See https://vercel.com/docs/frameworks/vite
hey are you using bun.js?
hey are you using bun.js?
Not that I'm aware of
@duncan1a Are you still facing this issue? FYI, your Github link throws 404.
hey man may that was your nodejs version error, consider to open pull request on nodejs official github repo or use other nodejs version, i don't have enough information about your error but you probably try.
I just noticed that my vercel was node 12, quite old. I haven't had a chance to deploy again (at a company off-site), but will try asap
I just noticed that my vercel was node 12, quite old. I haven't had a chance to deploy again (at a company off-site), but will try asap
that's the problem. change nodejs version on package.json and closed this issue if solved.
hmmm, if I build my blog branch, which is for vercel, then I get he same error locally (didn't notice that before, bt maybe I didn't build it since it wasn't the master branch)), but if I build the koyeb branch, which also has MongoDB then it builds fine. It's definitely the vercel build and not the node version
... I found this in node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@builder.io/qwik-city/adapters/vercel-edge/vite/index.cjs
However, adding {target: "node"} to the vercelEdgeAdapter in adapters/vercel-edge/vite.config.ts still gets the same error
@duncan1a Did you solve this issue?
@duncan1a Did you solve this issue?
No
Hello @duncan1a. Please provide a minimal reproduction using a GitHub repository or StackBlitz.
Here is why we really need a minimal reproduction.
Issues marked with STATUS-2: needs reproduction will be automatically closed if they have no activity within 14 days.
Thanks 🙏
@duncan1a your repro leads to a 404 now.
but if I build the koyeb branch, which also has MongoDB then it builds fine. It's definitely the vercel build and not the node version If vercel can build with MongoDB could you update the issue title or close and open a new issue with a narrower MRE?
I deleted the repo some time ago - closing this now