-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import
from process
left behind in browser-targeted output
#7904
Comments
We could definitely support that: https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/js/core/src/env_replacer.rs |
Unfortunately, I don't know Rust... |
…`process.env` in Parcel - see: parcel-bundler/parcel#7904
Parcel is currently [unable to perform static analysis](parcel-bundler/parcel#7904) on the `in` operator applied to `process.env`, for the purposes of bundling the module. (Parcel is a front-end to SWC, so this most likely affects SWC as well.) Would you mind making this very minor change? It should work exactly the same - `enabled` is `true` by default, so `FORCE_COLOR` only has an effect when set to exactly `0`. It's a bit simpler and avoids mutations, so maybe a bit easier to read anyhow. 🙂
I've tested the
I've pushed it to a branch here. Apparently it's due to these references in
Is it supposed to handle (Should I file a separate issue for this?) |
Currently, it doesn't (so this is more of a feature request than a bug report).
Yes |
🐛 bug report
I'm trying to build a "universal" ES6 library - meaning, it should be able to load in modern Node, modern browsers, and probably Deno too.
The addition of
browserslist
appears to resolve allprocess.env
references statically - however, one reference looks like it was left behind, and the resulting module leads with:Shouldn't there be an error or warning for this, when the bundler knows it's building for a browser context, and the resulting build still has a Node specific
import
left in it?It appears the lingering
process
import comes from theansi-colors
, which contains this:Perhaps the
in
operator is not supported by static analysis?Or maybe the static analysis is getting confused by the presence of two nested tests?
🎛 Configuration (.babelrc, package.json, cli command)
My attempted
package.json
(and the project) is located here.🤔 Expected Behavior
Probably at least a warning or error, for either one or both of these:
process
references from a browser target.process.env
reference via static analysis for any reason.Ideally, static analysis should probably be enhanced to support this though? It looks like both
rollup
andwebpack
are capable of handling this case, so it would probably be best to have parity with that, as it's rather influential on the ecosystem already.😯 Current Behavior
(see above)
💁 Possible
SolutionWorkaroundI could submit a PR to
ansi-colors
and try to make it more compatible with Parcel's static analysis. (assuming it's possible to somehow rewrite thatprocess.env
check in a way that works the same?)🔦 Context
(see project referenced above.)
💻 Code Sample
(see references above.)
🌍 Your Environment
parcel@2.4.1
,@parcel/packager-ts@2.4.1
,@parcel/transformer-typescript-types@2.4.1
v16.14.2
The text was updated successfully, but these errors were encountered: