Reputation: 18545
I have a class test.ts
export class Test1 {
}
I have another class usetest.ts
in same folder that gives me error
import Test = require("test");//error say cannot find test
var t = new Test.Test1();
but if I specify
import Test = require("./test");//no error
var t = new Test.Test1();
then there is no error. What the "./" is necessary? Can we omit it in anyway?
Upvotes: 4
Views: 1647
Reputation: 276085
What the "./" is necessary?
Yes
Can we omit it in anyway?
Not easily. It needs to be in ./node_modules/test.ts
for require('test')
to just work.
Here is the complete nodejs module spec : https://nodejs.org/api/modules.html#modules_all_together ... its a bit much but if you are doing NodeJS development I highly recommend reading it 🌹
Upvotes: 3