JoeStanton/babel-transform-js-to-jsx

SyntaxError: Unexpected token {

Closed this issue ยท 4 comments

Thanks for the tool! Not sure if I'm doing something completely wrong here, but it seems that node doesn't like something about js-to-jsx when I use it from the command line...

$ cat autocomplete.js | lsc -cb --no-header | js-to-jsx 
/usr/local/lib/node_modules/babel-js-to-jsx/index.js:1
let {DOM} = require("react");
    ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:54:16)
    at Module._compile (module.js:375:25)
    at Module._extensions..js (module.js:406:10)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel-js-to-jsx/node_modules/babel-register/lib/node.js:138:7)
    at Module.load (module.js:345:32)
    at Function.Module._load (module.js:302:12)
    at Module.require (module.js:355:17)
    at require (internal/module.js:13:17)
    at /usr/local/lib/node_modules/babel-js-to-jsx/node_modules/babel-core/lib/transformation/file/options/option-manager.js:191:20
    at Array.map (native)

I think I broke this today, sorry. Getting the packaging right for the built in executable has been a little difficult as Babel actually transpiles the plugins on the fly too. It seems to not be doing so here.

Many third party babel plugins have an npm prepublish script to avoid the additional complexity around this but I've not tried it yet.

Can you try again with 2.0.3? Just pushed it to npm. The actual fix was this commit: e974cbb

If that doesn't work out, I'd recommend rolling your own script for now, importing as a CommonJS module. Let me know if it doesn't work and I can provide an example.

๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘

Can you please publish this as a es5 modules.

I'm trying to use the plug-in without having to transpile this modules, since babel by default doesn't attempt to transpile node_modules folder by default.

I'm trying to use the following snippet:

require("babel-core").transform(code, {
  plugins: ["js-to-jsx", "syntax-jsx"],
}).code

https://babeljs.io/docs/usage/require/

FYI @JoeStanton

I'm still getting the unexpected token error with v2.1.0.

I'm just trying to do a basic test such as:
cat file.js | js-to-jsx

Am I doing something wrong?