foundation-sites: Babel doesn't work on default foundation-zurb-template

[19:04:27] Failed to load external module babel-register
[19:04:27] Requiring external module babel-core/register

This is on Debian sid’s builds of node and npm, version 4.3.1 and 1.4.21 respectively.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 42 (10 by maintainers)

Commits related to this issue

Most upvoted comments

To address a few things that I don’t believe have been mentioned:

  • gulp-babel will read the configuration you have in .babelrc if it exists, even if you pass even a configuration object when calling $.babel() in your Gulpfile.
  • For Gulp to read a Gulpfile as ES6, it needs a .babelrc. Therefore, both your JavaScript build process and your Gulpfile have to be transpiled with the same Babel configuration.
  • Babel’s es2015 preset includes a CommonJS plugin, and one of the things it does is rename any top-level use of this to undefined.
  • what-input uses an AMD wrapper that uses a top-level this, which Babel was then breaking. The error in the console reads something like Cannot read property "root" of undefined.
  • You can configure the CommonJS plugin to not convert this to undefined by setting the allowTopLevelThis option to true.
  • However, if you load plugins through a preset, you can’t configure anything inside of the preset.
  • You could remove the CommonJS plugin, but then that breaks the Gulpfile because it uses import statements.

So this is a tangled web. Thankfully, we’re getting close to an out:

  • The creator of what-input published a version 2.0 which just strips the AMD wrapper entirely. That means it wouldn’t be affected by Babel’s CommonJS plugin.
  • That means we can go back to using the es2015 plugin with all the defaults set.
  • That means the .babelrc and package.json are much simpler: two Babel dependencies, one Babel preset.

We’ve already merged a PR to bump our what-input dependency to 2.0, so we can deploy that with a version 6.2.1.

Sorry for the hassle, friends, and thanks for your patience 😃