node doesn't recognize es2015?
I'm trying to run the relay-starter-kit updateSchema.js with babel-node. It seems that it doesn't recognize the arrow functions:
> SyntaxError: .../build/updateSchema.js: Unexpected token (10:9)
8 |
9 | // Save JSON of full schema introspection for Babel Relay Plugin to use
> 10 | async () => {
| ^
I've tried to add the preset "stage-0" to ".babelrc" which fix that error but instead I get:
SyntaxError: .../build/updateSchema.js: Unexpected token (23:1)
21 | );
22 | }
> 23 | }();
| ^
Is this not recognizing the es2015? Or is it a error in my schema? The script "updateSchema.js" is from the relay-starter-kit.
Everything else runs fine and "babel-node" doesn't seem to have a problem with the rest of my application which is written in es2015.
EdIT: I've tried now to just download the relay-starter-kit and run "npm run update-schema" and it works out of the box.
Did you required babel-core
at entry point?
First npm install --save-dev babel-core
then open entry point file of your application
and then required babel-core
by require("babel-core");
This syntax worked on babel 5, but it should throw a syntax error because it is a non-standard arrow function call syntax: arrow function discussion
So, the fix is like this:
(async () => {
var result = await (graphql(Schema, introspectionQuery));
if (result.errors) {
console.error('ERROR: ', JSON.stringify(result.errors, null, 2));
} else {
fs.writeFileSync(
path.join(__dirname, '../data/schema.json'),
JSON.stringify(result, null, 2)
);
}
})();
链接地址: http://www.djcxy.com/p/32944.html
上一篇: Browserify和ES6 / ES2015课程(babel compiller)
下一篇: 节点不识别es2015?