nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
929 stars 194 forks source link

Resolve location of `@vue/apollo-composable` using node module resolution algo #522

Closed zenflow closed 1 year ago

zenflow commented 1 year ago

Fixes #519

See https://github.com/nuxt-modules/apollo/issues/519#issuecomment-1616157758 for analysis of the problem and suggested solution (which this PR implements)

Tested this solution using patch-package and the module (@vue/apollo-composables main module) resolves correctly when it's at either location (./node_modules/@vue/apollo-composable or ./node_modules/@nuxtjs/apollo/node_modules/@vue/apollo-composable)

netlify[bot] commented 1 year ago

Deploy Preview for apollo-module canceled.

Name Link
Latest commit 144e395035c27ad109d09b9a7246f7f2fb7238e9
Latest deploy log https://app.netlify.com/sites/apollo-module/deploys/64a0a540aa71eb0008c4d8ad
zenflow commented 1 year ago

Closing as I was a bit premature opening this.

I get the following error when I try to actually visit a page that uses an apollo composable (using vite dev server):

[7:01:55 PM] Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\matt_\Documents\dev\lucid-chat\node_modules\@nuxtjs\apollo\node_modules\@apollo\client\core\index.js from C:\Use
rs\matt_\Documents\dev\lucid-chat\node_modules\@nuxtjs\apollo\node_modules\@vue\apollo-composable\dist\index.js not supported.
Instead change the require of C:\Users\matt_\Documents\dev\lucid-chat\node_modules\@nuxtjs\apollo\node_modules\@apollo\client\core\index.js in C:\Users\matt_\Documents\dev\lucid-chat
\node_modules\@nuxtjs\apollo\node_modules\@vue\apollo-composable\dist\index.js to a dynamic import() which is available in all CommonJS modules.
    at C:\Users\matt_\Documents\dev\lucid-chat\node_modules\@nuxtjs\apollo\node_modules\@vue\apollo-composable\dist\index.js:259:30
    at ViteNodeRunner.directRequest (file:///C:/Users/matt_/Documents/dev/lucid-chat/node_modules/vite-node/dist/client.mjs:326:11)
    [...]

The first line of the stack trace points to this:

// node_modules/@nuxtjs/apollo/node_modules/@vue/apollo-composable/dist/index.js
// ...
var import_core = __toModule(require("@apollo/client/core/index.js")); // <-- line 259
// ...