vuejs / apollo

🚀 Apollo/GraphQL integration for VueJS
http://apollo.vuejs.org
MIT License
6.01k stars 521 forks source link

Not work with 3.2.25 #1517

Open keyiis opened 10 months ago

keyiis commented 10 months ago

Describe the bug I add Apollo client in main.ts, like this:

const app = createApp(App);

// HTTP connection to the API
    let url = import.meta.env.VITE_NODE_API + '/graphql';
    console.log(url)
    const httpLink = createHttpLink({
        // You should use an absolute URL here
        uri: url,
    })

    // Cache implementation
    const cache = new InMemoryCache()

    // Create the apollo client
    const apolloClient = new ApolloClient({
        link: httpLink,
        cache,
    })

    const apolloProvider = createApolloProvider({
        defaultClient: apolloClient,
    })

app.use(apolloProvider).use(ElementPlus).use(Vant).use(store).use(router).mount('#app')

Then I run my vue project. The following error occurs

Versions vue:3.2.25 vue-apollo: I don't konw @apollo/client:3.8.7

My package.json { "name": "client", "private": true, "version": "0.0.0", "scripts": { "dev": "vite --config vite.config.ts", "build": "vue-tsc --noEmit && vite --config vite.config.ts build", "preview": "vite preview" }, "dependencies": { "@apollo/client": "^3.8.7", "@element-plus/icons-vue": "^2.0.10", "@neysf/qiyu-web-sdk": "^1.1.1", "@vant/touch-emulator": "^1.4.0", "@vue/apollo-composable": "^4.0.0-beta.11", "@vue/apollo-option": "^4.0.0-beta.9", "axios": "^0.27.2", "dayjs": "^1.11.7", "element-plus": "^2.2.32", "graphql": "^16.8.1", "graphql-tag": "^2.12.6", "string-similarity-js": "^2.1.4", "ts-md5": "^1.3.1", "vant": "^4.0.10", "vue": "^3.2.25", "vue-router": "^4.0.15", "vuex": "^4.0.2" }, "devDependencies": { "@vitejs/plugin-vue": "^2.3.3", "sass": "^1.52.1", "sass-loader": "^13.0.0", "typescript": "^4.5.4", "vite": "^2.9.9", "vue-tsc": "^0.34.7" } }

keyiis commented 10 months ago

I discovered the cause of the error, When vue compile node_modules/graphql/jsutils/instanceOf.mjs,the globalThis.process.env.NODE_ENV will be converted to globalThis."development" .

1699259113469
petunmar commented 9 months ago

I discovered the cause of the error, When vue compile node_modules/graphql/jsutils/instanceOf.mjs,the globalThis.process.env.NODE_ENV will be converted to globalThis."development" . 1699259113469

I also ran into this problem and it is currently being discussed in a thread on the graphql-js repository. You can find the ongoing discussion here: graphql/graphql-js#3978.

There I found a workaround that worked for me. By changing the check from:

globalThis.process && globalThis.process.env.NODE_ENV === 'production'

to

globalThis.process && globalThis.process.env['NODE_ENV'] === 'production'

I was able to resolve the problem in my project. Although this is just a temporary solution until a more permanent fix is implemented in the library.