developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.05k stars 362 forks source link

Failed to resolve the module node:* when target ≠ "node" #1036

Open donmccurdy opened 1 year ago

donmccurdy commented 1 year ago

Similar to https://github.com/developit/microbundle/issues/989, but now occurring only when Microbundle's target is not Node.js. I'm compiling a library that runs in both Node.js and a browser, and the library contains dynamic imports for node built-ins like 'fs', executed only in Node.js.

When importing fs I can add the following to my package.json and everything works fine:

"browser": {
  "fs": false,
  "path": false
},

However, using node:fs, the same thing does not work, and warnings appear with:

"browser": {
  "node:fs": false,
  "node:path": false
},
Failed to resolve the module node:fs

Microbundle v0.15.1, Node.js v18.12.1.

machao7 commented 1 year ago

any progress?

rschristian commented 1 year ago

@machao7 You can subscribe to the issue and get notified whenever there's progress. When there is, you'd see it here.

Honestly I'd recommend avoiding the browser field spec anyhow, package.json#exports has completely eclipsed it. Output separate browser & Node bundles, don't rely upon bundlers patching out your imports. It's always been a pretty bad hack for isomorphic modules.

That being said, likely just need to bump @rollup/plugin-node-resolve, looks to be related to https://github.com/rollup/plugins/issues/1048 & https://github.com/rollup/plugins/pull/1124