nuxt-modules / apollo

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

Error in nuxt.config.ts #489

Open thibaultchazal opened 1 year ago

thibaultchazal commented 1 year ago

Environment

Describe the bug

I have this error in VSCode:

Argument of type '{ typescript: { strict: true; }; modules: string[]; apollo: { clients: { default: { httpEndpoint: string; }; }; }; }' is not assignable to parameter of type 'NuxtConfig'.
  Object literal may only specify known properties, and 'apollo' does not exist in type 'NuxtConfig'.ts(2345)

My nuxt.config.ts look like that


export default defineNuxtConfig({
    typescript: {
        strict: true
    },
    modules: [
        '@nuxt/typescript-build',
        '@nuxtjs/apollo'
    ],
    apollo: {
        clients: {
            default: {
                httpEndpoint: process.env.BACKEND_URL || "http://localhost:1337/graphql",
            }
        }
    }
})

### Expected behaviour

I followed the official Getting Started https://apollo.nuxtjs.org/getting-started/quick-start

I'd like not to have error!

### Reproduction

_No response_

### Additional context

_No response_

### Logs

_No response_
packet-sent commented 1 year ago

I had the same issue, and solved it by deleting the node_modules folder and then running npm install.

rossi-jeff commented 1 year ago

so if deleteing node_modules does NOT work is my only option to use fetch api?

pschaub commented 11 months ago

You can solve this by adding @nuxtjs/apollo to the modules in nuxt.config.ts and afterwards running npx nuxt prepare to generate the types.

The types for nuxt modules must be generated, see:

The default minimal nuxt starter kit adds a postInstall script to package.json to run this automatically after npm install:

"scripts": {
  "postinstall": "nuxt prepare"
}
JessicaSachs commented 1 month ago

Is this a Nuxt problem or a Nuxt Apollo problem? Should @nuxtjs/apollo run nuxt prepare in postinstall?