Comments (4)
Are you using a bundler? A bundler might be inserting the entire process.env
object there, although it shouldn't. The code could also do !!process.env
if that was a problem worth preventing.
from reflect-metadata.
This definitely sounds like something a bundler is doing, which is unfortunate because the point of the other checks on that line are to only test for the environment variable in a host that actually supports it.
The code could also do
!!process.env
if that was a problem worth preventing.
Are you indicating that !!process.env
would bypass the bundler injecting an object here? It's already checking for the presence of env
via &&
:
const usePolyfill = typeof process === "object" && process.env && process.env["REFLECT_METADATA_USE_MAP_POLYFILL"] === "true";
// ^^^^^^^^^^^
So unless the !!
is some kind of heuristic a bundler recognizes, I'm not sure it will be much help.
The only other thing I could think to do is do something like process["en" + "v"]
, assuming that's enough to bypass a bundler.
from reflect-metadata.
True - I would assume/hope that a bundler that is providing process
would know that process
and process.env
are always an object, and thus the boolean would be replaced by true
and then go through DCE.
I'd still love to know which bundler tho, since that sounds like a pretty bad bug.
from reflect-metadata.
I'm using webpack
via nx
and am also encountering this problem.
nx
uses webpack's DefinePlugin
to automatically load all envars starting with NX_
into process.env
. As a result, if reflect-metadata
is included in the bundle, all the the envars also get included in the bundler's output.
Granted this behaviour is not a bug; however, it does result in some undesirable outcomes (envars being included into your bundle). Given that process.env
is used to check if polyfills should be included, could you expose an additional polyfill-less entrypoint (eg. import 'reflect-metadata/no-polyfills';
)? This would also probably address #73
from reflect-metadata.
Related Issues (20)
- getMetadata("design:paramtypes") returns [ undefined ] HOT 2
- Inferred types are set as Object HOT 4
- TypeError: Cannot read property 'Reflect' of undefined HOT 1
- Tag new version in upstream HOT 4
- How to get the parameter type of ParameterDecorator
- "design:type" return undefined if types are defined out of order. HOT 2
- Importable version of `reflect-metadata` that does not shim globals. HOT 6
- index.d.ts file, what is the type of function metadata HOT 1
- The use of "indexOf" is not rigorous enough
- Since language specification published, this repo should be archived HOT 4
- Reflect metadata circular dependency HOT 2
- CJS / ES Module? HOT 12
- Throw type error when TS class decorator returns an object. HOT 7
- How to import (using absolute paths import feature of typescript) an module which use reflect-metadata?
- Remove dynamic evaluation to access globalThis in "lite" mode HOT 1
- Infinite loop in v0.2.0 HOT 2
- Package subpath './Reflect' is not defined by "exports" HOT 3
- Stage 3 decorators additional implementation HOT 1
- Reflect-Metadata update breaks Nest+TypeORM HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reflect-metadata.