qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[🐞] Vercel build fails with mongodb - Cannot bundle Node.js built-in "stream"

Open duncan1a opened this issue 2 years ago • 13 comments

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

duncan1a avatar Jan 15 '24 16:01 duncan1a

Isn't this a duplicate of #5714

wmertens avatar Jan 15 '24 17:01 wmertens

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 avatar Jan 15 '24 17:01 duncan1a

@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

wmertens avatar Jan 17 '24 15:01 wmertens

hey are you using bun.js?

01582 avatar Jan 21 '24 15:01 01582

hey are you using bun.js?

Not that I'm aware of

duncan1a avatar Jan 22 '24 08:01 duncan1a

@duncan1a Are you still facing this issue? FYI, your Github link throws 404.

balaji-sivasakthi avatar Jan 23 '24 19:01 balaji-sivasakthi

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.

01582 avatar Jan 24 '24 19:01 01582

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

duncan1a avatar Jan 24 '24 20:01 duncan1a

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.

01582 avatar Jan 25 '24 12:01 01582

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

duncan1a avatar Jan 25 '24 19:01 duncan1a

... I found this in node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@builder.io/qwik-city/adapters/vercel-edge/vite/index.cjs

image after looking through this PR https://github.com/BuilderIO/qwik/pull/5414/files

However, adding {target: "node"} to the vercelEdgeAdapter in adapters/vercel-edge/vite.config.ts still gets the same error

image

duncan1a avatar Jan 25 '24 19:01 duncan1a

@duncan1a Did you solve this issue?

gioboa avatar Jun 17 '24 16:06 gioboa

@duncan1a Did you solve this issue?

No

duncan1a avatar Jun 17 '24 18:06 duncan1a

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 🙏

github-actions[bot] avatar Aug 17 '24 09:08 github-actions[bot]

@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?

maiieul avatar Aug 17 '24 09:08 maiieul

I deleted the repo some time ago - closing this now

duncan1a avatar Aug 19 '24 08:08 duncan1a