Mohammad Dayyan
Mohammad Dayyan

Reputation: 22411

can not find module TypeScript error message?

I created a TypeScript's class and published it on npm
https://www.npmjs.com/package/mds.persian.calendar

I installed it in a Angular project as the following command:
npm install mds.persian.calendar --save

It installed successfully, and I can see the mds.persian.calendar folder in node_modules folder but when I want to use it in my TypeScript file as the following code, it alert can not find module
import { MdsPersianCalendar } from 'MdsPersianCalendar';

How should I use it?

Upvotes: 0

Views: 223

Answers (1)

Markus
Markus

Reputation: 4149

In mds.persian.calendar/package.json this config is missing:

{
    ...
    "main": "./mds.persian.calendar.js",
    "types": "./mds.persian.calendar.d.ts"
}

That's why you need to reference this module relative e.g. like this

//./wwwroot/ts/main.ts

// This doesn't work
//import { MdsPersianCalendar } from 'mds.persian.calendar';

import { MdsPersianCalendar } from '../../node_modules/mds.persian.calendar/mds.persian.calendar';

let calendar = new MdsPersianCalendar();
calendar.now

Upvotes: 2

Related Questions