fix: transforming node:builtin when targeting commonjs
↪️ Pull Request
Fixes #8049
Currently, Parceljs silently uses
node:builtininside commonjs although this doesn't work. There should be a transformer that converts this to normal nodejs imports when targeting commonjs.import { execFileSync } from "node:fs"🤔 Expected Behavior
const { execFileSync } = require("fs")😯 Previous Behavior
const { execFileSync } = require("node:fs")
💻 Examples
🚨 Test instructions
✔️ PR Todo
- [ ] Added/updated unit tests for this change
- [ ] Filled out test instructions (In case there aren't any unit tests)
- [x] Included links to related issues/PRs
Can you please add a test?
I did, but I realized that this doesn't fix the issue fully. I added an alias property. The architecture of the code does not allow to do alias transformation inside the resolving code. It also seems that AssertGroup doesn't accept something like an alias.
One cruel workaround is to create simple built-in Node packages that export the module, and then use them for resolving node: when the output is commonjs:
For example,
node:fs can be resolved to this package:
@parcel/node-builtin-fs
exports = require("fs")
@devongovett do you want to go with the workaround route, or do you want to change the API of the resolver?