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

155
Views
Access __webpack_exports__ from a webpack bundle using "new Function(code)"

I'm looking for a way to access classes inside a compiled webpack bundle after using new Function() to execute the bundle.

For example, I have

export class TestClass {
   constructor() {
      console.log('Success');
   }
}

Which webpack compiles to:

/******/ (() => { // webpackBootstrap
/******/    "use strict";
   var __webpack_exports__ = {};
   // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
   (() => {
      var exports = __webpack_exports__;
      /*!*********************!*\
        !*** ./src/test.ts ***!
        \*********************/

      Object.defineProperty(exports, "__esModule", ({ value: true }));
      exports.TestClass = void 0;
      class TestClass {
         constructor() {
            console.log('Success');
         }
      }
      exports.TestClass = TestClass;

   })();

   /******/
})()
   ;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFBQSxNQUFhLFNBQVM7SUFDbkI7UUFDRyxPQUFPLENBQUMsR0FBRyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0lBQzFCLENBQUM7Q0FDSDtBQUpELDhCQUlDIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vc3RyYXRlZ3kvc3JjL1VzZXJzL2FkbWluL2NvZGUvYm90bWFpbi9zdHJhdGVneS9zcmMvdGVzdC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgY2xhc3MgVGVzdENsYXNzIHtcbiAgIGNvbnN0cnVjdG9yKCkge1xuICAgICAgY29uc29sZS5sb2coJ1N1Y2Nlc3MnKTtcbiAgIH1cbn0iXSwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiIn0=

If I load this bundle from the file system and execute it using new Function(), how can I then access TestClass?

I would like to do something like:

const code = await fs.readFile(path, 'utf8')
const rawModule = new Function(code)();

const instance = new rawModule.TestClass();

I basically need to access __webpack_exports__. Is there some webpack loader or other way I can do this?

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!