nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Preset cloudflare not ignoring optional require()

Open zendagin opened this issue 2 years ago • 3 comments

Environment

node v16.14.2 nitropack 0.4.7

Reproduction

https://stackblitz.com/edit/github-dfijad?file=nuxt.config.ts

run npm run build

Describe the bug

Default preset works well when building with package with optional require() (in my case, mogodb)., but not with preset cloudflare.

It throws

ERROR Rollup error: Cannot resolve "snappy/package.json" from "/home/projects/github-dfijad/node_modules/mongodb/lib/deps.js" and externals are not allowed!

ERROR Cannot resolve "snappy/package.json" from "/home/projects/github-dfijad/node_modules/mongodb/lib/deps.js" and externals are not allowed!

Additional context

Code snap from mongodb sdk

try {
  // Ensure you always wrap an optional require in the try block NODE-3199
  Snappy = require('snappy');
  try {
    (Snappy as any)[PKG_VERSION] = parsePackageVersion(require('snappy/package.json'));
  } catch {} // eslint-disable-line
} catch {} // eslint-disable-line

Logs

No response

zendagin avatar Jun 15 '22 10:06 zendagin

I am experiencing thesame issue as above . thing is i can not even tell what is causing the error. the package referred to does not exist in my project

shiftlabs1 avatar Jun 27 '22 18:06 shiftlabs1

Same issue with the Cloudflare preset here :/

warflash avatar Jul 28 '22 17:07 warflash

Same issue when upgraded nuxt to 3.0.0-rc.8-27699522.e38e1de https://stackblitz.com/edit/github-dfijad-x7236k?file=nuxt.config.ts,app.vue,package.json

victorkwok97 avatar Sep 01 '22 11:09 victorkwok97

MongoDB is not compatible with worker platforms. Please follow up via #949

pi0 avatar Feb 16 '23 10:02 pi0