module-builder icon indicating copy to clipboard operation
module-builder copied to clipboard

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

Open prof-schnitzel opened this issue 10 months ago • 4 comments

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


prof-schnitzel avatar Feb 11 '25 12:02 prof-schnitzel

Stackblitz link for the reproduction: Stackblitz

github-actions[bot] avatar Feb 11 '25 12:02 github-actions[bot]

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.)

danielroe avatar Feb 22 '25 20:02 danielroe

@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?

prof-schnitzel avatar Feb 23 '25 00:02 prof-schnitzel

Funnily enough, I'm having this exact problem in https://github.com/nuxt/ui/pull/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

sandros94 avatar Mar 07 '25 15:03 sandros94