apollo icon indicating copy to clipboard operation
apollo copied to clipboard

Error in nuxt.config.ts

Open thibaultchazal opened this issue 1 year ago • 4 comments

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_

thibaultchazal avatar Mar 08 '23 14:03 thibaultchazal

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

packet-sent avatar Mar 19 '23 02:03 packet-sent

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

rossi-jeff avatar May 02 '23 13:05 rossi-jeff

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:

  • https://nuxt.com/docs/guide/concepts/typescript#auto-generated-types
  • https://nuxt.com/docs/api/commands/prepare

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

"scripts": {
  "postinstall": "nuxt prepare"
}

pschaub avatar Dec 25 '23 03:12 pschaub