Skip to content

injecting external-helpers in a node app #7357

@travi

Description

@travi

Choose one: is this a bug report or feature request? (docs?) bug report

I'm trying to use a package that assumes that the external-helpers are available as a global. From the docs, I should be able to inject them to global in my node app by using require("babel-core").buildExternalHelpers();. However, use of that still results in the following error: ReferenceError: babelHelpers is not defined

Babel/Babylon Configuration (.babelrc, package.json, cli command)

Since the buildExternalHelpers() function needs to run before the package is imported and my app uses es module imports, I'm using a bootstrap file as an entry point that is ignored from transpilation and just tries to inject the helpers before loading the actual app:

require("babel-core").buildExternalHelpers();
const app = require('./app');

Expected Behavior

babelHelpers should be added to global so that it is available for the package that assumes it is available there.

from the docs:

This injects the external helpers into global.

Current Behavior

babelHelpers is not made available on global, resulting in ReferenceError: babelHelpers is not defined

Possible Solution

The docs also mention generating a helpers file with ./node_modules/.bin/babel-external-helpers [options] > helpers.js. It wasn't obvious to me that this file could be imported to accomplish the same goal as buildExternalHelpers() until I started reading the source of that file. Importing that file instead does work for my app. I'll need this file elsewhere, so I'll likely just continue importing that instead, even if there is a way to use buildExternalHelpers().

With that approach, my bootstrap file has the following contents instead:

require('../../vendor/babel-helpers');
const app = require('./app');

Your Environment

software version(s)
Babel 6.26.0
node 8.9.4
npm 5.6.0
Operating System macOS High Sierra

Forum

While I was still trying to find a working solution, I was trying to find the best place to ask questions. The website still links to a discourse forum that no longer seems to exist. It'd be a good idea to either remove the link from the site or at least have it link to somewhere that describes the currently recommended approach for getting that type of help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Docs.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions