mercredi 28 mars 2018

I have an enum in my Typescript / Ember 3.1 app and I am getting import errors at runtime. What's going on?

I have an ember component that is importing an enum type as follows:

import { StateNames, CardSummary } from '../../types/snowcat/state-types'

the type file is as follows:

export enum CardState {
  error = 'error',
  new = 'new',
  okay = 'okay',
  warning = 'warning',
}

I'm then using the enum as follows in the component:

  @computed('cardSummary.cardState')
  get type(): string {
    if ([CardState.new, CardState.okay, CardState.warning].includes(this.cardSummary.cardState)) {
      return 'info'
    }
    return 'error'
  }

Everything seems fine with the code. I am not getting any TypeScript errors when the code builds, but I am getting a runtime error:

loader.js:247 Uncaught Error: Could not find module `types/snowcat/state-types` imported from `snowcat/models/certificate`
    at missingModule (loader.js:247)
    at findModule (loader.js:258)
    at Module.findDeps (loader.js:168)
    at findModule (loader.js:262)
    at requireModule (loader.js:24)
    at r (loader.js:176)
    at ember-data.js:39
    at Array.forEach (<anonymous>)
    at getDsModels (ember-data.js:36)
    at getModels (ember-data.js:66)

What's going on? How do I fix this?




Aucun commentaire:

Enregistrer un commentaire