1

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?

ScubaSteve
  • 7,724
  • 8
  • 52
  • 65
  • Please share code for the module file as well as the model file in order to understand it correctly. – Utkarsh Jul 12 '21 at 02:38

2 Answers2

1

numerals and @types/numeral are different packages.

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

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

Michael Kang
  • 52,003
  • 16
  • 103
  • 135
  • I was following this (http://www.alternatestack.com/development/app-development/angular2-using-3rd-party-libraries/) as a guide. I tried just @types/numeral and still get the error. – ScubaSteve Jul 12 '21 at 03:03
  • don't use @types/numeral, just read the NPM packge README: https://www.npmjs.com/package/numerals – Michael Kang Jul 12 '21 at 03:04
1

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.

ScubaSteve
  • 7,724
  • 8
  • 52
  • 65