Reputation: 333
have two node projects as X,Y. X has a typescript class calculator.ts and its exported in index.ts and X's package json has property of typings as below.
"typings": "dist/src/index.d.ts"
node project Y imports calculator as below
import {Calculator} from 'X';
but it throws error
internal/modules/cjs/loader.js:583 throw err; ^
Error: Cannot find module 'X' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
it works when its imported from absolute path.
import {Calculator} from 'X/dist/src/calculator';
Upvotes: 0
Views: 223
Reputation: 333
main
field of X's package.json should point to the dist/src/index.js
to resolve exported classes at run time.
https://docs.npmjs.com/files/package.json#main
Upvotes: 1