1

I've got this index.ts file I'm transpiling to index.js with babel.

And I need a specific require to be at the top of the file.

https://www.npmjs.com/package/module-alias

You can see from the module-alias doc that that line should be called one time at the main file, before any other code.

enter image description here

index.ts

require("module-alias/register");     // <--- THIS LINE NEEDS TO COME BEFORE ANY CODE

// REST OF THE FILE

But babel is adding a bunch of stuff before that line in the transpiled version.

index.js

Object.defineProperty(exports, "__esModule", { value: true});

function _interopRequireDefault(obj) { ... }

function _getRequireWildcardCache() { ... }

function _interopRequireWildcard(obj) { ... }

// SOME OTHER STUFF

require("module-alias/register");   // THE LINE HAS MOVED DOWN TO HERE

Is there a config or some workaround I can do to make sure that line stays on top of the result file?

That line is not working in that position. It really needs to be on top. When I manually move it to the top, everything works fine.

cbdeveloper
  • 27,898
  • 37
  • 155
  • 336

0 Answers0