Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Reexporting @types/[email protected] from a .cjs file crashes #2522

Closed

Description

Stack trace

panic: Diagnostic emitted without context

goroutine 78 [running]:
github.com/microsoft/typescript-go/internal/transformers/declarations.throwDiagnostic({0x2, {0x0, 0x0, 0x0}, {0xc00000a090, 0xa}, 0xc000142008, {0xc0002280c0, 0x32}})
        github.com/microsoft/typescript-go/internal/transformers/declarations/transform.go:226 +0x4d
github.com/microsoft/typescript-go/internal/transformers/declarations.(*SymbolTrackerImpl).handleSymbolAccessibilityError(0xc00141e200, {0x2, {0x0, 0x0, 0x0}, {0xc00000a090, 0xa}, 0xc000142008, {0xc0002280c0, 0x32}})
        github.com/microsoft/typescript-go/internal/transformers/declarations/tracker.go:179 +0xc3
github.com/microsoft/typescript-go/internal/transformers/declarations.(*SymbolTrackerImpl).TrackSymbol(0xc00141e200, 0xc00170d408?, 0x7ff6ceea5c85?, 0x60?)
        github.com/microsoft/typescript-go/internal/transformers/declarations/tracker.go:162 +0xc5
github.com/microsoft/typescript-go/internal/checker.(*SymbolTrackerImpl).TrackSymbol(0xc001700240, 0xc001116e78, 0xc000142008, 0xc09e8)
        github.com/microsoft/typescript-go/internal/checker/symboltracker.go:39 +0x42
github.com/microsoft/typescript-go/internal/checker.(*NodeBuilderImpl).lookupSymbolChain(0xc00061c150, 0xc001116e78, 0xc09e8, 0x1)
        github.com/microsoft/typescript-go/internal/checker/nodebuilderimpl.go:953 +0x3b
github.com/microsoft/typescript-go/internal/checker.(*NodeBuilderImpl).symbolToTypeNode(0xc00061c150, 0xc00170e180?, 0xc09e8, 0x0)
        github.com/microsoft/typescript-go/internal/checker/nodebuilderimpl.go:516 +0x48
github.com/microsoft/typescript-go/internal/checker.(*NodeBuilderImpl).typeToTypeNode(0xc00061c150, 0xc00141e200?)
        github.com/microsoft/typescript-go/internal/checker/nodebuilderimpl.go:3030 +0x1a0c
github.com/microsoft/typescript-go/internal/checker.(*NodeBuilderImpl).serializeTypeForDeclaration(0xc00061c150, 0xc0001102a0, 0x800081c0d?, 0x7ff6cfb3c2c0?)
        github.com/microsoft/typescript-go/internal/checker/nodebuilderimpl.go:2022 +0x265
github.com/microsoft/typescript-go/internal/checker.(*NodeBuilder).SerializeTypeForDeclaration(0xc001700180, 0xc0001102a0, 0xc000306e00, 0x25500000002?, 0x310a38?, 0x0?, {0x7ff6cfb3c2c0?, 0xc00141e200?})
        github.com/microsoft/typescript-go/internal/checker/nodebuilder.go:108 +0x54
github.com/microsoft/typescript-go/internal/checker.(*EmitResolver).CreateTypeOfDeclaration(0xc000326120, 0xc0002026e0, 0xc0001102a0, 0xc000142008, 0x81c0d, 0x8, {0x7ff6cfb3c2c0, 0xc00141e200})
        github.com/microsoft/typescript-go/internal/checker/emitresolver.go:942 +0x174
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).ensureType(0xc0006262a0, 0xc0001102a0, 0x17?)
        github.com/microsoft/typescript-go/internal/transformers/declarations/transform.go:1174 +0x28d
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitDeclarationStatements(0xc0006262a0, 0xc0001102a0)
        github.com/microsoft/typescript-go/internal/transformers/declarations/transform.go:1033 +0x87a
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0x7ff6cf026ad1?, 0x255d931a0e0?)
        github.com/microsoft/typescript-go/internal/transformers/declarations/transform.go:195 +0xfc
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitSlice(0xc000696360, {0xc000134080, 0x3, 0x3})
        github.com/microsoft/typescript-go/internal/ast/visitor.go:148 +0xc2
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNodes(0xc000696360, 0xc00012a260)
        github.com/microsoft/typescript-go/internal/ast/visitor.go:99 +0x37
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).transformSourceFile(0xc0006262a0, 0xc000142008)
        github.com/microsoft/typescript-go/internal/transformers/declarations/transform.go:263 +0x3a
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visitSourceFile(0xc0006262a0, 0xc000142008)
        github.com/microsoft/typescript-go/internal/transformers/declarations/transform.go:250 +0x1a7
github.com/microsoft/typescript-go/internal/transformers/declarations.(*DeclarationTransformer).visit(0xc00101a060?, 0x16?)
        github.com/microsoft/typescript-go/internal/transformers/declarations/transform.go:178 +0xe5
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitNode(0xc001704000?, 0xc0002026e0?)
        github.com/microsoft/typescript-go/internal/ast/visitor.go:51 +0x27
github.com/microsoft/typescript-go/internal/ast.(*NodeVisitor).VisitSourceFile(...)
        github.com/microsoft/typescript-go/internal/ast/visitor.go:36
github.com/microsoft/typescript-go/internal/transformers.(*Transformer).TransformSourceFile(...)
        github.com/microsoft/typescript-go/internal/transformers/transformer.go:40
github.com/microsoft/typescript-go/internal/compiler.(*emitter).emitDeclarationFile(0xc001704000, 0xc000142008, {0xc00101a060, 0x16}, {0x0, 0x0})
        github.com/microsoft/typescript-go/internal/compiler/emitter.go:203 +0x25b
github.com/microsoft/typescript-go/internal/compiler.(*emitter).emit(0xc001704000)
        github.com/microsoft/typescript-go/internal/compiler/emitter.go:48 +0x5e
github.com/microsoft/typescript-go/internal/compiler.(*Program).Emit.func2()
        github.com/microsoft/typescript-go/internal/compiler/program.go:1437 +0x1b8
github.com/microsoft/typescript-go/internal/core.(*parallelWorkGroup).Queue.func1()
        github.com/microsoft/typescript-go/internal/core/workgroup.go:40 +0x13
sync.(*WaitGroup).Go.func1()
        sync/waitgroup.go:239 +0x4a
created by sync.(*WaitGroup).Go in goroutine 77
        sync/waitgroup.go:237 +0x73

Steps to reproduce

See the repository at Knagis/tsgo-micromatch-panic

test.cjs:

/** @type {typeof import("micromatch") | undefined} */
let micromatch;

module.exports.micromatch = micromatch;

Activity

  1. Knagis commented on Jan 16, 2026

    @Knagis
    Author

    in case it helps

    • 7.0.0-dev.20251027.1 can compile the code without crashes
    • 7.0.0-dev.20251029.1 crashes
  2. added
    Domain: Declaration Emit
    on Jan 18, 2026
  3. Knagis commented on Feb 11, 2026

    @Knagis
    Author

    Still crashes with 7.0.0-dev.20260211.1

    panic: Diagnostic emitted without context
    
    goroutine 5800 [running]:
    github.com/microsoft/typescript-go/internal/transformers/declarations.throwDiagnostic({0x2, {0x0, 0x0, 0x0}, {0xc00aa118d0, 0xa}, 0xc00280ce08, {0xc00682bf80, 0x55}})
            github.com/microsoft/typescript-go/internal/transformers/declarations/transform.go:226 +0x4d
    github.com/microsoft/typescript-go/internal/transformers/declarations.(*SymbolTrackerImpl).handleSymbolAccessibilityError(0xc00149a500, {0x2, {0x0, 0x0, 0x0}, {0xc00aa118d0, 0xa}, 0xc00280ce08, {0xc00682bf80, 0x55}})
            github.com/microsoft/typescript-go/internal/transformers/declarations/tracker.go:173 +0xc3
    github.com/microsoft/typescript-go/internal/transformers/declarations.(*SymbolTrackerImpl).TrackSymbol(0xc00149a500, 0x7ff7afe0c1c0?, 0xc0034c2570?, 0x88befa8?)
            github.com/microsoft/typescript-go/internal/transformers/declarations/tracker.go:156 +0xc5
    ....
    
  4. RyanCavanaugh commented on Apr 14, 2026

    @RyanCavanaugh
    Member

    No longer crashes, but now an error (6.0 does not error):

    test.cjs:2:1 - error TS4032: Property 'micromatch' of exported interface has or is using name 'Micromatch' from private module '"D:/Throwaway/yolo2/node_modules/@types/micromatch/index"'.
    
    2 let micromatch;
      ~~~
    
  5. weswigham commented on May 5, 2026

    @weswigham
    Member

    Aside from the long-fixed panic, the new error mentioned doesn't repro anymore. Presumably this was fixed by #3449 properly enabling node reuse of the type annotation on the let.

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

Metadata

Metadata

Labels

CrashDomain: Declaration Emit

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions