apollo
apollo copied to clipboard
Error in nuxt.config.ts
Environment
- Operating System:
Darwin
- Node Version:
v16.18.1
- Nuxt Version:
3.2.3
- Nitro Version:
2.2.3
- Package Manager:
[email protected]
- Builder:
vite
- User Config:
typescript
,modules
,apollo
- Runtime Modules:
@nuxt/[email protected]
,@nuxtjs/[email protected]
- Build Modules:
-
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_
I had the same issue, and solved it by deleting the node_modules folder and then running npm install
.
so if deleteing node_modules does NOT work is my only option to use fetch api?
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"
}