felipecrv / jsx-requirejs-plugin

A RequireJS plugin for loading and compiling (with r.js) JavaScript files containing JSX.
MIT License
270 stars 44 forks source link

r.js 2.1.11 cannot build scripts with latest jsx #8

Closed victor-homyakov closed 10 years ago

victor-homyakov commented 10 years ago

Exception at https://github.com/philix/jsx-requirejs-plugin/blob/master/js/JSXTransformer-0.10.0.js#L10386

Tracing dependencies for: all.components
Error: Error: Loader plugin did not call the load callback in the build:
jsx:
  jsx!components/helloworld: Error: fromText eval for jsx!components/helloworld failed: SyntaxError: Unexpected token <
http://requirejs.org/docs/errors.html#fromtexteval
Module loading did not complete for: all.components, components/component.menu, components/extension.menu
    at Function.build.checkForErrors (C:\Code\js\build\r.js:27237:19)

In order to build I surrounded _dereq_('source-map') with try .. catch:

  if (options.sourceMap) {
    try {
      var SourceMapGenerator = _dereq_('source-map').SourceMapGenerator;
      state.g.sourceMap = new SourceMapGenerator({file: 'transformed.js'});
    } catch (e) {
      // ignored
    }
  }
felipecrv commented 10 years ago

@victor-homyakov what's the name of components/helloworld (it should use the .jsx extension)? r.js evals all .js files which will of course fail in the presence of <Tags>.

victor-homyakov commented 10 years ago

Extension is .js. Everything works fine in dev mode, only r.js build fails (more exactly, fails the code _dereq_('source-map')).

felipecrv commented 10 years ago

Extension is .js.

Should be .jsx.

Everything works fine in dev mode, only r.js build fails

As expected. As I said, r.js evals every .js file it finds, for us to be able to preprocess a JS file in r.js we have to use a different extension to tell r.js that its content is not JS.