This is a basic test involving async/await, where I have created a module with a simple class to handle delays
mymodule.ts
:
export class foo {
public async delay(t: number) {
console.log("returning promise");
return new Promise( resolve => setTimeout(resolve, t));
};
};
This is the top-level TypeScript file used to call the function:
hello.ts
:
import { foo } from './mymodule'
let f = new foo();
console.log("start");
await f.delay(4000);
console.log("done");
Although it builds without errors, when running the resulting hello.js with node (>node hello.js), an error is encountered:
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)
...
If I modify the import statement to include ".js", like so
import { foo } from './mymodule.js'
, then everything works as expected.
E:\tsdev\test\out>node hello.js
start
returning promise
done
Trying different configurations in tsconfig and package files has not resolved this issue. Any help will be greatly appreciated.
Shawn
I've attempted various modifications to the tsconfig and package files.