Cannot find module 'babel-plugin-transform-es2015-modules-commonjs'

Viewed 2008

I swapped from babel-preset-es2015 to babel-preset-env and made the related changes in other places:

.babelrc:

{
  "presets": ["env", "react"]
}

But now I'm getting the error:

Cannot find module 'babel-plugin-transform-es2015-modules-commonjs'

when I'm running a webworker that transpiles code in the following way:

ww.bundle.js (path/to/runner.js --export-to--> path/to/ww.js --browserify-bundled--> ww.bundle.js):

const babel = require('babel-core');
const env = require('babel-preset-env');

const esFive = babel.transform(testCode, { presets: [env] }).code;

Before, I had the following:

const babel = require('babel-core');
const es2015 = require('babel-preset-es2015');

const esFive = babel.transform(testCode, { presets: [es2015] }).code;

and it worked fine.

I believe the preset needed to be explicitly imported because ww.bundle.js couldn't locate .babelrc in the / directory.

If I try simply with:

const babel = require('babel-core');

const esFive = babel.transform(testCode, { presets: ['env'] }).code;

I once again get the error message from my earlier troubles:

Error: Couldn't find preset "env" relative to directory "/"

0 Answers
Related