最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - Parcel Build Failure: "Got Unexpected Null" Error When Exporting a Namespace with Enums - Stack O

programmeradmin1浏览0评论

I'm encountering a build error in my package. I've created a minimal reproduction of the issue here: .

Background

I have a namespace called GLOBALENUMS defined as follows:

export namespace GLOBALENUMS {
  export enum DROPDOWNDATA {
    EXTERNAL_PARTNERS = 'EXTERNAL_PARTNERS',
  }
  export enum PROCESSMAPNODETYPE {
    PROCESSGROUP = 'PROCESSGROUP',
    PROCESS = 'PROCESS',
  }
}

I then created an interface that refers to one of the enum types:

import { GLOBALENUMS } from "../global-enums";

export interface Process {
  id: number;
  processName?: string;
  processMapType?: GLOBALENUMS.PROCESSMAPNODETYPE;
}

At the main index.ts file, I export the namespace and the interface:

// global enums
export { GLOBALENUMS } from './ts';

// interfaces
export type { Process } from './ts/interfaces';

The Issue

When running yarn build (using Parcel for bundling), I get the following error:

@parcel/transformer-typescript-types: Got unexpected null

Error: Got unexpected null
    at nullthrows (/home/xxxx/Documents/git/ts-export/node_modules/nullthrows/nullthrows.js:7:15)
    at TSModuleGraph.propagate (/home/xxxx/Documents/git/ts-export/node_modules/@parcel/transformer-typescript-types/lib/TSModuleGraph.js:221:48)
    at shake (/home/xxxx/Documents/git/ts-export/node_modules/@parcel/transformer-typescript-types/lib/shake.js:37:35)
    at /home/xxxx/Documents/git/ts-export/node_modules/@parcel/transformer-typescript-types/lib/TSTypesTransformer.js:119:33
    ... (rest of error)

Curiously, if I comment out the line that references the enum in the Process interface:

export interface Process {
  id: number;
  processName?: string;
  // processMapType?: GLOBALENUMS.PROCESSMAPNODETYPE;
}

the build succeeds. This leads me to believe that exporting the GLOBALENUMS namespace is causing the issue, though I'm not sure why.

Questions

  1. Why is this happening?
  2. What would be a recommended workaround or solution to properly export the namespace and interface without triggering this error?

Note:- I want to group all enums in a single namespace. this is just a small example.

Any help or suggestions would be greatly appreciated!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论