#How to properly disable auto imports

9 messages · Page 1 of 1 (latest)

lunar widget
#

Since this my fifth time (or so) experiencing issues with nuxt auto-importing the wrong thing (without me or TS noticing) I wanted to disable auto imports all together. Since I struggle to do so correctly, I want to ask three questions:

What did I try?

I added the following to my nuxt config, but things are still broken:

  imports: {
    autoImport: false,
  },

1. Duplicated imports XXX
I still get errors like Duplicated imports "createError", the one from "#app" has been ignored, although I thought I disabled auto import. Why?

2. Typescript
Disabling auto-imports does not seem to work properly in connection with TS. I have cases where my typescript errors, although I need the line to run. i.e.:

import { fromNodeMiddleware } from '#imports';

errors with Module '"#imports"' has no exported member 'fromNodeMiddleware'., but if I remove the line and try to run I get the following runtime error: [worker reload] [worker init] defineNitroPlugin is not defined

I have other cases where I typescript fails to give errors. i.e. I have to import useRuntimeConfig from #imports manually to prevent getting a useRuntimeConfig is not defined runtime error (which is expected) , but TS fails to detect the issue during build time.

3. Where to import Nuxt / Nitro utilities from?
There are some nuxt / nitro utils that I have no idea where to import from if not from #imports. i.e. useRuntimeConfig, definePageMeta, defineNitroPlugin or fromNodeMiddleware. From where do I import those?

Thanks a lot in advance 🙃

nimble sphinx
lunar widget
atomic forum
#

I have a large application that disables auto-importing. But I don’t suffer from the issues you’ve outlined. IDE issues are often an isolated issue, something that’s very hard to reproduce without stepping into your shoes.

In regards to magic paths, there’s no real magic here. These are virtual modules that make it easier for end-users, as much as internal usage, to idiomatically communicate between varying environments (I.e. server/client). Life would be much more complicated without them.

lunar widget
#

would you mind sharing your config?

atomic forum
lunar widget
#

I jsut have the default setup, which is automatically generated when initializing a new project 🙈

#

so no tsconfig for the server directory