Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
Prevent babel from transpiling `global` variable

My script will be executed by the Android app Tasker, which injects its own value for global that is a function that gets called like const val = global('%variableName').

I'm bundling this script with Webpack & Babel, and Babel generates this code:

t.g = (function () {
  if ('object' == typeof globalThis) return globalThis
  try {
    return this || new Function('return this')()
  } catch (t) {
    if ('object' == typeof window) return window
  }
})()

And then swaps out global(...) with t.g(...). I'd like to prevent this part of the transpilation altogether.

My babel config looks like:

module.exports = {
  presets: [
    '@babel/preset-typescript',
    [
      '@babel/preset-env',
      {
        "targets": {
          "node": true
        }
      },
    ],
  ],
}

I added the preset-env configuration in an attempt to fix this, but no luck. I have also tried using ts-loader instead, but the results are the same. Hopefully I don't need to write my own babel plugin to post-process this in order to swap in some code like t.g = global.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!