QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.84k stars 1.31k forks source link

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

Closed duncan1a closed 2 months ago

duncan1a commented 10 months ago

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/mongodb@4.17.2/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/mongodb@4.17.2/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/mongodb@4.17.2/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/mongodb@4.17.2/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/rollup@4.9.1/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
16:35:13.562 | at Object.error (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.1/node_modules/rollup/dist/es/shared/node-entry.js:18454:20)
16:35:13.562 | at Object.resolveId (file:///vercel/path0/node_modules/.pnpm/vite@5.0.10_@types+node@20.10.5/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:28998:34)
16:35:13.562 | at Object.handler (file:///vercel/path0/node_modules/.pnpm/vite@5.0.10_@types+node@20.10.5/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67017:19)
16:35:13.562 | at file:///vercel/path0/node_modules/.pnpm/rollup@4.9.1/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/rollup@4.9.1/node_modules/rollup/dist/es/shared/node-entry.js:18539:28)
16:35:13.562 | at async resolveId (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.1/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/rollup@4.9.1/node_modules/rollup/dist/es/shared/node-entry.js:17622:15)
16:35:13.562 | at async file:///vercel/path0/node_modules/.pnpm/vite@5.0.10_@types+node@20.10.5/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
wmertens commented 10 months ago

Isn't this a duplicate of #5714

duncan1a commented 10 months ago

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

wmertens commented 10 months ago

@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

01582 commented 10 months ago

hey are you using bun.js?

duncan1a commented 9 months ago

hey are you using bun.js?

Not that I'm aware of

balaji-sivasakthi commented 9 months ago

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

01582 commented 9 months ago

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.

duncan1a commented 9 months ago

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

01582 commented 9 months ago

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.

duncan1a commented 9 months ago

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 commented 9 months ago

... I found this in node_modules/.pnpm/@builder.io+qwik-city@1.3.1_@types+node@20.10.5/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
gioboa commented 5 months ago

@duncan1a Did you solve this issue?

duncan1a commented 5 months ago

@duncan1a Did you solve this issue?

No

github-actions[bot] commented 3 months ago

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 🙏

maiieul commented 3 months ago

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

duncan1a commented 2 months ago

I deleted the repo some time ago - closing this now