{"record":{"id":"0a4a5270f719b252","repo":"evanw/esbuild","slug":"unexpected-newline-after-type","errorCode":null,"errorMessage":"Unexpected newline after \"type\"","messagePattern":"Unexpected newline after \"type\"","errorType":"panic","errorClass":"LexerPanic","httpStatus":null,"severity":"error","filePath":"internal/js_parser/js_parser.go","lineNumber":7185,"sourceCode":"\t\t\t\t\tp.log.AddError(&p.tracker, logger.Range{Loc: logger.Loc{Start: asyncRange.End()}},\n\t\t\t\t\t\t\"Unexpected newline after \\\"async\\\"\")\n\t\t\t\t\tpanic(js_lexer.LexerPanic{})\n\t\t\t\t}\n\t\t\t\tp.lexer.Expect(js_lexer.TFunction)\n\t\t\t\topts.isExport = true\n\t\t\t\treturn p.parseFnStmt(loc, opts, true /* isAsync */, asyncRange)\n\t\t\t}\n\n\t\t\tif p.options.ts.Parse {\n\t\t\t\tswitch p.lexer.Identifier.String {\n\t\t\t\tcase \"type\":\n\t\t\t\t\t// \"export type foo = ...\"\n\t\t\t\t\ttypeRange := p.lexer.Range()\n\t\t\t\t\tp.lexer.Next()\n\t\t\t\t\tif p.lexer.HasNewlineBefore && p.lexer.Token != js_lexer.TOpenBrace && p.lexer.Token != js_lexer.TAsterisk {\n\t\t\t\t\t\tp.log.AddError(&p.tracker, logger.Range{Loc: logger.Loc{Start: typeRange.End()}},\n\t\t\t\t\t\t\t\"Unexpected newline after \\\"type\\\"\")\n\t\t\t\t\t\tpanic(js_lexer.LexerPanic{})\n\t\t\t\t\t}\n\t\t\t\t\tp.skipTypeScriptTypeStmt(parseStmtOpts{isModuleScope: opts.isModuleScope, isExport: true})\n\t\t\t\t\treturn js_ast.Stmt{Loc: loc, Data: js_ast.STypeScriptShared}\n\n\t\t\t\tcase \"namespace\", \"abstract\", \"module\", \"interface\":\n\t\t\t\t\t// \"export namespace Foo {}\"\n\t\t\t\t\t// \"export abstract class Foo {}\"\n\t\t\t\t\t// \"export module Foo {}\"\n\t\t\t\t\t// \"export interface Foo {}\"\n\t\t\t\t\topts.isExport = true\n\t\t\t\t\treturn p.parseStmt(opts)\n\n\t\t\t\tcase \"declare\":\n\t\t\t\t\t// \"export declare class Foo {}\"\n\t\t\t\t\topts.isExport = true\n\t\t\t\t\topts.lexicalDecl = lexicalDeclAllowAll\n\t\t\t\t\topts.isTypeScriptDeclare = true\n\t\t\t\t\treturn p.parseStmt(opts)","sourceCodeStart":7167,"sourceCodeEnd":7203,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/js_parser/js_parser.go#L7167-L7203","documentation":"In 'export type ...' (TypeScript), a newline immediately after 'type' is disallowed unless the next token is '{' or '*' (js_parser.go:7182). This guards against 'export\\ntype' being misread as a type alias.","triggerScenarios":"'export type\\nFoo = string' — a line break after 'type' not followed by '{' (namespace) or '*' (re-export all).","commonSituations":"Formatter wrapping 'export' and 'type' onto separate lines; refactor artifacts; confusion between 'export type' and a value export.","solutions":["Put the type name on the same line as 'export type'.","If you intended a namespace/type-group, follow 'type' with '{' on the same line."],"exampleFix":"// before\nexport type\nFoo = string\n// after\nexport type Foo = string","handlingStrategy":"validation","validationCode":"import \"github.com/evanw/esbuild/pkg/api\"\nres := api.Transform(src, api.TransformOptions{Loader: api.LoaderTS})\nfor _, m := range res.Errors {\n  if strings.Contains(m.Text, `Unexpected newline after \"type\"`) {\n    // a line break sits after 'export type' before the type name\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the type name on the same line as 'export type'.","Validate TypeScript with tsc before bundling.","Review formatter settings that wrap 'export type' declarations."],"tags":["syntax-error","parser","typescript","export","newline"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}