Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Everything from Nuxt 3 Runtime Config is unknown #110

Open
qkqk opened this issue Nov 21, 2024 · 8 comments · May be fixed by #127
Open

Everything from Nuxt 3 Runtime Config is unknown #110

qkqk opened this issue Nov 21, 2024 · 8 comments · May be fixed by #127

Comments

@qkqk
Copy link

qkqk commented Nov 21, 2024

With the latest version 0.7.0 the Nuxt 3 build fails, because all types from Runtime Config are unknown, removing the nuxt-applicationinsights from nuxt.config modules fixes this.

Also downgrading the lib to 0.6.0 resolves this.

Error example:

error TS2322: Type '{ 'server-token': unknown; }' is not assignable to type 'HeadersInit | undefined'.
Types of property ''server-token'' are incompatible.
Type 'unknown' is not assignable to type 'string | undefined'.

26 headers: {
~~~~~~~

@huang-julien
Copy link
Owner

Hello can you provide a reproduction please ?

you can use https://stackblitz.com/edit/nuxt-starter-uvbiaa?file=README.md .

I need at least the package.json with the lockfile n order to debug it

@qkqk
Copy link
Author

qkqk commented Nov 25, 2024

Yes, here's the reproduction: https://stackblitz.com/edit/nuxt-starter-geb6an?file=server%2Fplugins%2Fmongodb.ts

Steps:

  1. Create .env file and add MONGODB_URI=mongodb+srv into it
  2. See the "server/plugins/mongodb.ts" file - the env from useRuntimeConfig() is unknown

Then:
4. Remove 'nuxt-applicationinsights' from nuxt.config.ts modules
5. Go back to "server/plugins/mongodb.ts" file - the env from useRuntimeConfig() is now a string as it should be

@miltonlaufer
Copy link

I am having exactly the same issue, is there a fix coming? Thanks!

@huang-julien
Copy link
Owner

that's strange, I can't reproduce it from https://stackblitz.com/edit/nuxt-starter-geb6an?file=server%2Fplugins%2Fmongodb.ts

BTW V1 is coming soon. but i can do a release patch on 0.x if i can reproduce it.

@qkqk
Copy link
Author

qkqk commented Jan 31, 2025

It's still reproducible for me, when I open the link, I have the TS error, as soon as I remove the 'nuxt-applicationinsights' from nuxt.config.ts, the TS error goes away.

Tested the V1, still the same issue. Also I've found what's it caused by:

in src/runtime/types.d.ts on line 5 the declaration is incorrect, if you change it to:

declare module 'nuxt/schema' {

the types will start working.

@huang-julien
Copy link
Owner

So i finally understood why i couldn't reproduce it. I was using pnpm. The workaround for now is to use pnpm as we need to investigate this specific issue in nuxt first.

You can see the reason of augmenting @nuxt/schema instead of nuxt/schema here and here in nuxt

@huang-julien
Copy link
Owner

which version of node and npm are you using ?
So i do reproduce it on stackblitz with npm only, not pnpm. But i can't reproduce it locally with npm nor pnpm

@qkqk
Copy link
Author

qkqk commented Feb 3, 2025

I'm getting this issue on Node v20 and Node v22, did not test other versions. For packages Yarn 1.22 is used, but I don't think the issue is related to node or npm / yarn version.

Most likely the types are just incorrectly implemented, but I don't know the right way of doing it as I never developed a Nuxt module before. I just know that changing it back to nuxt/schema "fixes" the "TS unknown" issue.

Also when reproducing it, make sure that you are testing the types on server side (some server side plugin or some API endpoint) as I'm not sure if there's same issue on FE code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants