【发布时间】:2016-09-30 02:31:05
【问题描述】:
我一直在尝试将很多 Babel 功能引入到我主要是手动编写的 React / GraphQL 项目中。但我尝试使用这个构建脚本通过 schema.graphql 文件生成:
import fs from 'fs';
import path from 'path';
import { graphql } from 'graphql';
import { introspectionQuery, printSchema } from 'graphql/utilities';
import schema from '../server/schema';
let file_schema_json = path.join(__dirname, '../graphql/schema.json');
let file_schema_graphql = path.join(__dirname, '../graphql/schema.graphql');
// Save JSON of full schema introspection for Babel Relay Plugin to use
async function createJson( )
{
var result = await( graphql( schema, introspectionQuery ) );
if( result.errors )
{
console.error( 'ERROR! ' );
console.error( 'ERROR introspecting schema: ', JSON.stringify(result.errors, null, 2) );
}
else
{
fs.writeFileSync( file_schema_json, JSON.stringify(result, null, 2) );
console.log( 'Written: ' + file_schema_json );
}
}
// Save user readable type system shorthand of schema
fs.writeFileSync( file_schema_graphql, printSchema( schema ) );
console.log( 'Written: ' + file_schema_graphql );
createJson( );
然后我得到了:
/Users/lorm/projects/aggregated_centralized_api/node_modules/babel-core/lib/transformation/file/index.js:591
throw err;
^
SyntaxError: /Users/lorm/projects/aggregated_centralized_api/scripts/build-schema.js: Unexpected token (12:6)
10 |
11 | // Save JSON of full schema introspection for Babel Relay Plugin to use
> 12 | async function createJson( )
| ^
13 | {
14 | var result = await( graphql( schema, introspectionQuery ) );
15 | if( result.errors )
但我复制了我能想到的所有依赖项:
"dependencies": {
"babel-cli": "^6.8.0",
"babel-core": "^6.8.0",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-async-to-generator": "^6.8.0",
"babel-polyfill": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-relay-plugin": "^0.8.1",
"babel-relay-plugin-loader": "^0.8.1",
"babel-runtime": "^6.6.1",
"body-parser": "1.15.1",
"dataloader": "1.1.0",
"dotenv": "2.0.0",
"express": "4.13.4",
"express-graphql": "^0.5.3",
"graphql": "0.4.18",
"graphql-relay": "0.3.6",
"mongodb": "2.0.39",
"q": "1.4.1"
},
"devDependencies": {
"babel": "^5.8.3",
"babel-core": "^5.8.3",
"babel-eslint": "^4.0.5",
"babelify": "^6.1.1",
"babel-cli": "^6.8.0",
"babel-jest": "^12.0.2",
"babel-plugin-transform-runtime": "^6.8.0",
"babel-polyfill": "^6.8.0",
"eslint": "^0.24.0",
"eslint-plugin-react": "^3.2.2",
"flow-bin": "^0.22.1"
},
但是,好像 Babel 没有被触发?或者不知道如何阅读这种 Javascript?什么会导致这个错误?
【问题讨论】: