graphql-tag / loader:模块构建失败,出现GraphQLError:语法错误

时间:2018-11-04 12:46:21

标签: vue.js webpack graphql babel graphql-tag

我面临的奇怪问题。使用Vue-CLI3 npm run serve

具有以下配置:

// vue.config.js
module.exports = {
  chainWebpack: config => {
    // GraphQL Loader
    config.module
      .rule('graphql')
      .test(/\.graphql$/)
      .use('graphql-tag/loader')
      .loader('graphql-tag/loader')
      .end();
  }
};

和一个.graphql文件:

mutation AddOfficeMutation(
    $name: String
    $location: String
  ) {
    createOffice(
      input: {office: { name: $name, location: $location }}
    ) {
      office {
        id
        name
        location
      }
    }
  }

运行npm run serve时,出现以下错误:

ERROR  Failed to compile with 1 errors                                                                                                                                                           1:11:08 PM

 error  in ./src/graphql/AddOfficeMutation.graphql

Module build failed (from ./node_modules/graphql-tag/loader.js):
GraphQLError: Syntax Error: Unexpected Name "var"
    at syntaxError (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/error/syntaxError.js:24:10)
    at unexpected (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:1490:33)
    at parseDefinition (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:153:9)
    at many (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:1520:16)
    at parseDocument (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:113:18)
    at parse (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql/language/parser.js:48:10)
    at parseDocument (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql-tag/src/index.js:129:16)
    at gql (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql-tag/src/index.js:170:10)
    at Object.module.exports (/Users/danroc/Dropbox/projects/tal-firebase/client-vue/node_modules/graphql-tag/loader.js:44:18)

 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/AddOfficeForm.vue?vue&type=script&lang=js& 29:0-69 59:18-35
 @ ./src/components/AddOfficeForm.vue?vue&type=script&lang=js&
 @ ./src/components/AddOfficeForm.vue
 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/AddOfficeView.vue?vue&type=script&lang=js&
 @ ./src/views/AddOfficeView.vue?vue&type=script&lang=js&
 @ ./src/views/AddOfficeView.vue
 @ ./src/router/routes.js
 @ ./src/router/router-config.js
 @ ./src/main.js
 @ multi ./node_modules/@vue/cli-service/node_modules/webpack-dev-server/client?http://192.168.0.99:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

使用:

  • “ graphql”:“ ^ 14.0.2”
  • “ graphql-tag”:“ ^ 2.10.0”

我慢慢假设这可能是Babel或Vue配置出现错误? 任何人都可以对此有所了解吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,似乎有2个装载机使飞机坠毁。

我已经安装了graphql-tagwebpack-graphql-loader

尝试卸载包含apollo或graphql的每个软件包,然后再次使用vue cli重新安装。 vue add apollo。它对我有用。