3

I'm working on bundling a project using webpack, and I'm doing so with this config that is compiled with babel 6 (node 5, npm 3):

import webpack from 'webpack';

export default {
  entry: './node_modules/graphql/graphql.js',
  output: {
    path: './build',
    filename: 'bundle.js',
    libraryTarget: "var",
    library: "graphql"
  },
  resolve: {
    extensions: ['', '.js']
  },
  devtool: 'eval'
};

However, with babel 6, this gives me an error when I run webpack:

Output filename not configured.

If I translate this code back to es5:

var webpack = require('webpack');

module.exports = {
  entry: './node_modules/graphql/graphql.js',
  output: {
    path: './build',
    filename: 'bundle.js',
    libraryTarget: "var",
    library: "graphql"
  },
  resolve: {
    extensions: ['', '.js']
  },
  devtool: 'eval'
};

it works just fine.

My .babelrc file looks like this:

{
  "plugins": ["transform-es2015-modules-commonjs"]
}

and I have the following packages installed in the local node_modules:

├── babel@6.0.15
├── babel-core@6.1.2
├── babel-loader@6.0.1
├── babel-plugin-transform-es2015-modules-commonjs@6.1.3
├── babel-runtime@6.0.14
├── graphql@0.4.12
└── webpack@1.12.3

EDIT Upon further inspection of the code Babel spits out, I think my problem is the export default isn't getting properly transpiled to modules.export:

'use strict';

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

var _webpack = require('webpack');

var _webpack2 = _interopRequireDefault(_webpack);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = {
  entry: './node_modules/graphql/graphql.js',
  output: {
    path: './build',
    filename: 'bundle.js',
    libraryTarget: "amd",
    library: "graphql"
  },
  resolve: {
    extensions: ['', '.js']
  },
  devtool: 'eval'
};

How do I get Babel to properly transpile es6 module code to Node's module format with the transform-es2015-modules-commonjs plugin?

Leonid Beschastny
  • 50,364
  • 10
  • 118
  • 122
Nathan Jones
  • 4,904
  • 9
  • 44
  • 70
  • check out my other answer here: http://stackoverflow.com/questions/33549895/i-cant-use-es6-in-webpack-config-file . This may work if you just want to be able to trans-pile the config file. – 4m1r Nov 06 '15 at 18:40

1 Answers1

0

Looks like this capability has been deprecated from Babel.

https://github.com/babel/babel/issues/2212

Nathan Jones
  • 4,904
  • 9
  • 44
  • 70