drd / jsxlate-loader

Webpack loader for jsxlate
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

TypeError: Object #<CodeGenerator> has no method 'ExportNamedDeclaration' #1

Open zbyte64 opened 8 years ago

zbyte64 commented 8 years ago

When I add jsxlate to my webpack loaders I get the following stack trace:

ERROR in ./src/experiments/admin/application.jsx
Module build failed: Error transforming /home/jason/Repos/project-webinator/maker/src/experiments/admin/application.jsx (Original exception: TypeError: Object #<CodeGenerator> has no method 'ExportNamedDeclaration')
    at CodeGenerator.generateStatement (/home/jason/Repos/project-webinator/maker/node_modules/jsxlate/node_modules/escodegen-wallaby/escodegen.js:2631:33)
    at CodeGenerator.Statement.Program (/home/jason/Repos/project-webinator/maker/node_modules/jsxlate/node_modules/escodegen-wallaby/escodegen.js:1703:43)
    at CodeGenerator.generateStatement (/home/jason/Repos/project-webinator/maker/node_modules/jsxlate/node_modules/escodegen-wallaby/escodegen.js:2631:33)
    at generateInternal (/home/jason/Repos/project-webinator/maker/node_modules/jsxlate/node_modules/escodegen-wallaby/escodegen.js:2652:28)
    at Object.generate (/home/jason/Repos/project-webinator/maker/node_modules/jsxlate/node_modules/escodegen-wallaby/escodegen.js:2720:18)
    at generate (/home/jason/Repos/project-webinator/maker/node_modules/jsxlate/lib/jsxlate.js:1080:22)
    at Object.transformMessageNodes (/home/jason/Repos/project-webinator/maker/node_modules/jsxlate/lib/jsxlate.js:337:12)
    at Object.module.exports (/home/jason/Repos/project-webinator/maker/node_modules/jsxlate-loader/index.js:17:49)
 @ ./src/experiments/admin/index.jsx 9:19-43

Here is my webpack config:

var Common = {
  cache: true,
  entry: _.merge({
    newIndustry: './src/new-industry/index.jsx',
    admin: './src/experiments/admin/index.jsx',
    common: './less/common.less',
    vendors: [ //package up the layout code to a standalone
    'lodash',
    'react',
    //'immutable',
    //'query-string',
    'refluxxor',
    //'babel-runtime',
    'isomorphic-fetch',
    'webinator-assets',
    ]
  }, experiment_entrypoints),
  output: {
    path: path.join(__dirname, "dist"),
    publicPath: "dist",
    filename: '[name].min.js',
    chunkFilename: "[id].bundle.js"
  },
  module: {
    loaders: [
    { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", 'css-loader') },
    { test: /\.less$/, loader: ExtractTextPlugin.extract("style-loader", 'css-loader!less-loader') },
    { test: /\.jsx$/, loaders: ['babel-loader?stage=1&optional[]=runtime', 'jsxlate-loader'] },
    { test: /\.js$/, loader: 'babel-loader?stage=1&optional[]=runtime', exclude: /(bower_components|node_modules)/ },
    { test: /\.json$/, loader: 'json-loader' },
    ],
    noParse: /(\.min\.js)/
  },
  resolve: {
    // Tell webpack to look for required files in bower and node
    modulesDirectories: ['bower_components', 'node_modules'],
    extensions: ["", ".webpack.js", ".web.js", ".js", ".jsx", ".json", ".css"],
    alias: {
      underscore: 'lodash',
    }
  },
  devtool: 'source-map',
  debug: true,
  lessLoader: {
    lessPlugins: [
      new LessPluginCleanCSS({advanced: true}),
      new LessPluginAutoPrefix({browsers: ["last 2 versions"]}),
    ]
  }
}
drd commented 8 years ago

Thanks for the report!

The problem actually lies in the fork (of a fork) of escodegen that jsxlate relies on. That project is here: https://github.com/drd/escodegen/tree/wallaby and it is a matter of it missing a code generator for ExportNamedDeclaration … it looks like you have a different kind of export statement than is currently supported. It appears that estools/escodgen now supports these statements, so it should be fairly easy to fix.

I would certainly welcome a PR against my fork of escodegen, but if not I'll see when I can get around to it. I'm also in the process of a (compatible) rewrite of jsxlate which will not depend on escodgen in this way.

In the meantime, if you are able to re-structure your export statements then jsxlate would work as-is. I'd be happy to help with that if you show me the offending export in ./src/experiments/admin/application.jsx.

zbyte64 commented 8 years ago

My exports look like:

export var Root = React.createClass({
  ...
})
drd commented 8 years ago

Ok, so if you change that to:

var Root = React.createClass({
  ...
})

export Root;

That should change it to the non-offending ExportDeclaration statement type and work.