Giter VIP home page Giter VIP logo

Comments (4)

ljharb avatar ljharb commented on August 17, 2024

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.

rbuckton avatar rbuckton commented on August 17, 2024

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.

ljharb avatar ljharb commented on August 17, 2024

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.

janeklb avatar janeklb commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.