Using enum from custom TypeScript module throws “Cannot read properties of undefined”

I have an Angular app from which I needed to separate some enums and models to shared lib so I can use same models in Firebase Functions.

I created my new module using Typescript:

// package.json
{
  "name": "@invoice-maker/shared",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "build": "tsc"
  },
  "devDependencies": {
    "@types/node": "^20.8.5",
    "typescript": "^5.2.2"
  }
}
// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ES2020",
    "declaration": true,
    "declarationDir": "./dist/types",
    "outDir": "./dist/lib",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
// enums/invoice-type.ts
export enum InvoiceType {
  Local = 1,
  Foreign = 2,
}
//index.ts
import { InvoiceType } from "./enums/invoice-type";
/* Other interfaces and enums */

export {
  InvoiceType,
  /* Other interfaces and enums */
};

I run npx tsc to compile it. I installed that library inside my Angular app with npm i, I see it in package.json, I can import it’s types, VS Code is recognizing everything. However when I compile app, I get in runtime:

core.mjs:11458 ERROR TypeError: Cannot read properties of undefined (reading 'Local')

My imports in Angular looks normal: import { InvoiceType } from '@invoice-maker/shared'; and there is no error from VS Code.

Is there anything I’m doing incorrect?

  • Can it be related to where you do import like '@invoice-maker/shared'. Did you check if it’s exists at all?

    – 




  • What do you mean by “if it’s exists”? How can I check that? You mean if .js file was generated?

    – 

Leave a Comment