Very simple test of async/await and I have a module that includes simple class to implement a delay function
mymodule.ts:
export class foo {
public async delay(t: number) {
console.log("returning prmise");
return new Promise( resolve => setTimeout(resolve, t));
};
};
Simple top-level TypeScript file to call the function:
hello.ts:
import { foo } from './mymodule'
let f = new foo();
console.log("start");
await f.delay(4000);
console.log("done");here
This builds fine but when I run the resulting hello.js with Node (node hello.js) I get:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'E:\tsdev\test\out\mymodule' imported from E:\tsdev\test\out\hello.js
Did you mean to import ../mymodule.js?
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:326:11)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
If I add ".js" to make the import import { foo } from './mymodule.js' it also builds just fine and now the application works as expected:
E:\tsdev\test\out>node hello.js
start
returning prmise
done
I tried various changes to tsconfig.json and package.json files.