3.0.0-rc.3
https://github.com/renyuanz/vue-cli-graphql-mocha-issue
vue create graphql-bug
yarn add graphql
graphql
in HelloWorld.spec.js
import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import { graphql } from 'graphql'
import HelloWorld from '@/components/HelloWorld.vue'
describe('HelloWorld.vue', () => {
it('renders props.msg when passed', () => {
const t = graphql();
const msg = 'new message'
const wrapper = shallowMount(HelloWorld, {
propsData: { msg }
})
expect(wrapper.text()).to.include(msg)
})
})
should run correctly
Failed to compile with 164 error(s)
Error in ./node_modules/graphql/index.mjs
Can't reexport the named export 'BREAK' from non EcmaScript module (only default export is available)
// ...
@renyuanz You probably are using a custom webpack extensions resolve config. Please look here on how to fix it; https://github.com/graphql/graphql-js/issues/1272
I just basically fixed it by configuring it like this in vue.config.js;
const config = {
configureWebpack: {
resolve: {
// .mjs needed for https://github.com/graphql/graphql-js/issues/1272
extensions: ['*', '.mjs', '.js', '.vue', '.json', '.gql', '.graphql'],
},
module: {
rules: [ // fixes https://github.com/graphql/graphql-js/issues/1272
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
],
},
},
};
module.exports = config;
@leovanhaaren You are the best!! Thanks for saving my day!
I tried to config webpack by using chainWebpack
but no luck.
Based on @leovanhaaren's advice, if you're using Vue CLI 3 so you have access to chainWebpack
in vue.config.js
, try this:
chainWebpack(config) {
config.module // optional
.rule('graphql')
.test(/\.graphql$/)
.use('graphql-tag/loader')
.loader('graphql-tag/loader')
.end()
config.module
.rule('mjs')
.test(/\.mjs$/)
.include.add(/node_modules/)
.end()
.type('javascript/auto')
.end()
config.resolve.extensions
.add('.mjs')
.add('.gql')
.add('.graphql')
.end()
},
Then the mysterous GraphQL module error should be gone.
Most helpful comment
I just basically fixed it by configuring it like this in vue.config.js;