Skip to content

Module build results in "error TS2307: Cannot find module or its corresponding type declarations." #519

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

Open
prof-schnitzel opened this issue Feb 11, 2025 · 4 comments

Comments

@prof-schnitzel
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v20.10.0
  • Nuxt Version: 3.15.4
  • CLI Version: 3.21.1
  • Nitro Version: 2.10.4
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://github.com/prof-schnitzel/nuxt-ts-bug-module/tree/main

Describe the bug

In my module.ts I have added the line export type * from './runtime/types' so that my nuxt module exports types that can be used in a consumer app. In the types file I only have this line: export * from '../components/MyDiv.vue'. But when running npm run prepack I get the error src/runtime/types/index.ts(1,15): error TS2307: Cannot find module '../components/MyDiv.vue' or its corresponding type declarations. Why? This seems to be a bug to me.

Additional context

No response

Logs

Copy link

Stackblitz link for the reproduction: Stackblitz

@danielroe danielroe transferred this issue from nuxt/nuxt Feb 22, 2025
@danielroe
Copy link
Member

The issue here is likely caused by you exporting those types from your module entrypoint. (However they should be treated as externals and not resolved further, so I regard it as a bug.)

@prof-schnitzel
Copy link
Author

@danielroe Yes, I want to use those types in the application that uses that module. Isn't it correct to export those types in the module entrypoint?

@sandros94
Copy link
Member

sandros94 commented Mar 7, 2025

Funnily enough, I'm having this exact problem in nuxt/ui#3479 only windows side.

EDIT:
for Nuxt UI I'm also having an issue while re-exporting the types of upstream validation libraries

import type { StandardSchemaV1 } from '@standard-schema/spec'
// ... unrelated vue imports
import type { ZodSchema } from 'zod'
import type { Schema as JoiSchema } from 'joi'
import type { ObjectSchema as YupObjectSchema } from 'yup'
import type { GenericSchema as ValibotSchema, GenericSchemaAsync as ValibotSchemaAsync, SafeParser as ValibotSafeParser, SafeParserAsync as ValibotSafeParserAsync } from 'valibot'
// ... unrelated util imports
import type { Struct as SuperstructSchema } from 'superstruct'

// ...

export type FormSchema<T extends object> =
  | ZodSchema
  | YupObjectSchema<T>
  | ValibotSchema
  | ValibotSchemaAsync
  | ValibotSafeParser<any, any>
  | ValibotSafeParserAsync<any, any>
  | JoiSchema<T>
  | SuperstructSchema<any, any>
  | StandardSchemaV1

// ...

Each package will trigger its own one (taking in example @standard-schema/spec):

ERROR  Expected ';', '}' or <eof> in A:\github\nuxt\ui\node_modules\.pnpm\@[email protected]\node_modules\@standard-schema\spec\dist\index.d.ts

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

No branches or pull requests

3 participants