Can't resolve 'numeral' in Angular app model

578 views Asked by At

I npm i numerals, then npm i @types/numeral.

I am trying to use numeral inside my price.model.ts file. So, I imported it: import * as numeral from 'numeral';

But, I'm getting this error: ./src/app/shared/models/price.model.ts:1:0-35 - Error: Module not found: Error: Can't resolve 'numeral' in '\src\app\shared\models'

Right now, I'm just using it to parse the number|string that is coming in. I plan to use it for arithmetic later.

private parseValue(value: number | string): number {
  let numeralValue = numeral(value).value();
  if (numeralValue === null) throw new Error(`${value} is Nan.`);

  return numeralValue.valueOf();
}

There's no squigglies prior to compile. I only get the error on ng serve.

Am I missing something?

2

There are 2 answers

2
Michael Kang On

numerals and @types/numeral are different packages.

If you want to use numerals, just import what you need:

import { Language, NumeralForm, convertNumberToNumeralForm } from 'numerals';

0
ScubaSteve On

The issue was that I installed "numerals" instead of "numeral". I needed both npm i numeral and npm i @types/numeral for it to work.