nuxt: shows type error on nuxt.config.ts for app meta, plugins, css, build, vite
Environment
Operating System: Windows_NT Node Version: v18.0.0 Nuxt Version: 3.3.3 Nitro Version: 2.3.2 Package Manager: npm@9.4.2 Builder: vite
Reproduction
https://github.com/iabirkhan/Nuxt-3-Minimal
Describe the bug
with default nuxt 3.3.3 setup or upgraded version shows type error in nuxt,config.ts.
- *** This type error shows on minimal setup:
Argument of type ‘{ app: { head: { charset: string; viewport: string; }; }; }’ is not assignable to parameter of type ‘NuxtConfig’. Object literal may only specify known properties, and ‘app’ does not exist in type ‘NuxtConfig’.ts(2345)
- *** Extending config also shows type error on plugins, css, build, vite
export default defineNuxtConfig({
// app, plugins, css, build, vite not working
app: {
head: {
title: "Nuxt 3 App",
charset: "utf-8",
viewport: "width=device-width, initial-scale=2",
},
}, // if app config removed plugins dosen't work
plugins: [], // shows error one after another
css: [],
build: {},
vite: {},
// modules, typescript working
modules: [],
typescript: {
strict: true,
},
});
Hopefully explained the problem clearly, please check.
Additional context
No response
Logs
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 8
- Comments: 30 (6 by maintainers)
I checked #20221 and eliminated this warning by installing
@types/node,typescriptandvue-tsc.This is confusing because I understand that the purpose of scaffolding is to reduce the amount of work required to initialize the project, can you tell me why it’s not built in?
I’ve tried
nuxi prepareit doesn’t work.👇️ with NPM
npm install --save-dev @types/node👇️ with YARN
yarn add @types/node --devThe problem occurring for some because Nuxt v3.3.3 dosen’t include ‘@types/node’ by default or missing.
Please check.
Look lot’s of people facing this issue, but it just a type error warning. It’s annoying I know, but doesn’t effect your dev.
Solution: if the problem consist even after solution above or fresh nuxt v3.4.3 installation that’s maybe reason of your ide or ide version (mine vscode). Try updating your ide to latest. Hopefully the problem will resolve.
Not elaborating because I’m outside and on phone. Will give time later.
I have a production app live and it’s fine.
It’s a shame! Nuxt 3 is not usable yet!
These packages helped me:
v.3.2.2 and v.3.3.3 - also have the same type of error: TS2345: Argument of type ‘bla-bla-bla’ is not assignable to parameter of type ‘NuxtConfig’. Object literal may only specify known properties, and ‘bla-bla-bla’ does not exist in type ‘NuxtConfig’.
did not help: remove .nuxt folder and running nuxi prepare or npx nuxi upgrade --force – with different combinations.
my app is working and the build is working but I see the red line “TS2345: Argument of type bla-bla-bla” always for the first config in my nuxt.config.ts file. I do not have a red error line only for modules block (if I just comment other configs and do it: remove .nuxt folder and running nuxi prepare or npx nuxi upgrade --force)
for other cases in my example, I have an error only for the first config if I even move the first config to the next line I will have an error on the first line((
full error in my case: TS2345: Argument of type ‘{ ssr: boolean; build: { transpile: string[]; }; css: string[]; i18n: { strategy: “prefix”; defaultLocale: string; lazy: false; locales: { code: string; iso: string; name: string; }[]; vueI18n: { locale: string; fallbackLocale: string; globalInjection: true; legacy: false; messages: { …; }; }; detectBrowserLanguag…’ is not assignable to parameter of type ‘NuxtConfig’. Object literal may only specify known properties, and ‘ssr’ does not exist in type ‘NuxtConfig’.
I could solve it by extending nuxt’s + node 20 tsconfig.json like the following:
package.json:
tsconfig.json:
@danielroe @lpknv
I know it’s not a “real” fix, but you could just rename the nuxt.config.ts file to nuxt.config.js as a temporary fix or just add the // @ts-ignore if those type error warnings are too annoying.
The top three packages should not be installed in a Nuxt 3 project.
Install typescript as a dev dependency;
npm install typescript --save-devI had reply too quickly. This made defineNuxtConfig not found:
So I remove “@tsconfig/node20/tsconfig.json” and simple install typescript as dev.
Note for who use Bun:
bun add -D typescriptcan resolve problem with nuxt3@yarin-zhang’s solution worked 🎉
Yes, kinda: use the
// @ts-ignorecomment as a temporary solution. I couldn’t find anything else useful.I can confirm this. I started new project on https://stackblitz.com/fork/github/nuxt/starter/tree/v3-stackblitz
After running
nuxi buildthere are type errors innuxt.config