Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

graphql-tag/loader: Module build failed with GraphQLError: Syntax Error

Weird issue I am facing. Using Vue-CLI3 npm run serve.

Have the following config:

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

and one single .graphql file:

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

when running npm run serve, I get the following error:

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

Using:

  • "graphql": "^14.0.2"
  • "graphql-tag": "^2.10.0"

I am slowly assuming this might be an error with my Babel or Vue config? Anyone can shed some light on this?

Thanks!

like image 847
Daniel da Rocha Avatar asked Jun 13 '26 20:06

Daniel da Rocha


1 Answers

I faced the same issue and it seemed that having 2 loaders make the crash.

I had installed graphql-tag and webpack-graphql-loader .

Try to uninstall every package that includes apollo or graphql and reinstall using vue cli again. vue add apollo. It worked for me.

like image 175
Dario Rusignuolo Avatar answered Jun 16 '26 17:06

Dario Rusignuolo