Closed aaronshaf closed 8 years ago
@aaronshaf which version of babel are you using?
6.0.15
Can't replicate this with babel 6.1.x but I notice that you didn't include the commonjs modules transformer (or the es2015 preset) in your config so it should have failed for different reasons. Leads me to suspect you have a .babelrc
file which might be overriding something, if so please post the contents here. Will reopen if you can provide a more detailed repro.
I am having this same issue. I have app.js:
require('babel-core/register')();
require('./bar.js');
And in bar.js:
let a: string = 'test';
With .babelrc:
{
"plugins": [
"typecheck"
],
"presets": [
"es2015"
]
}
When I run node app
, I get the following error:
C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\lib\transformation\file\index.js:540
throw err;
^
SyntaxError: C:/Users/Scott/Documents/GitHub/test/bar.js: Unexpected token (1:5)
←[0m> 1 | let a←[1m:←[22m string ←[1m=←[22m ←[31m'test'←[39m←[1m;←[22m
| ^←[0m
at Parser.pp.raise (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\parser\location.js:22:13)
at Parser.pp.unexpected (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\parser\util.js:91:8)
at Parser.pp.semicolon (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\parser\util.js:78:38)
at Parser.pp.parseVarStatement (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\parser\statement.js:405:8)
at Parser.pp.parseStatement (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\parser\statement.js:114:19)
at Parser.pp.parseBlockBody (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\parser\statement.js:527:25)
at Parser.pp.parseTopLevel (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\parser\statement.js:29:8)
at Parser.parse (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\parser\index.js:96:17)
at Object.parse (C:\Users\Scott\Documents\GitHub\test\node_modules\babylon\lib\index.js:44:50)
at File.parse (C:\Users\Scott\Documents\GitHub\test\node_modules\babel-core\lib\transformation\file\index.js:472:24)
If I remove the : string
portion, it runs fine. If I also just do babel app.js bar.js --out-dir dist
, I get the output:
app.js -> dist\app.js
SyntaxError: bar.js: Unexpected token (1:8)
> 1 | let name: string = 'test';
| ^
global babel-cli@6.2.0 (babel-core@6.2.1) babel-core@6.2.1 typecheck@3.0.2
I feel like I am missing something obvious here, but I cannot get even a basic example to run with the plugin.
@sgodwin424 please try adding babel-plugin-syntax-flow
to your list of plugins or babel-preset-react
to your list of presets then try again.
Thank you. Adding babel-preset-react
or babel-plugin-syntax-flow
and babel-transform-flow-strip-types
seems to work. I was under the impression that this plugin was standalone as the installation does not seem to suggest otherwise, but I suppose it makes sense that it would need other flow plugins.
Maybe this should be added to the installation section to avoid these issues? I have been wanting to use flowtype, but they do not support Windows yet, so when I found this plugin, I was quite thrilled to be able to use it in part. This is also the reason why I did not have the other flow plugins.
@sgodwin424 there's a weird issue with plugin ordering in babel6 which makes it impossible to specify that this plugin depends on those others automatically. I've added a note to the README in #56
I have the following in foo.js:
In bar.js:
Error: