This has been driving me crazy. How can I get typescript to compile the imported module correctly? My main.ts has import { AddListeners } from './listeners'; which is also a .ts file with export function AddListeners() but when compiled to main.js, this line doesn't change and node throws this error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\bugbe\Documents\VSCode\tricorder\dist\listeners' imported from C:\Users\bugbe\Documents\VSCode\tricorder\dist\main.js
Here is my tsconfig.json:
{
"compilerOptions": {
"esModuleInterop": true,
"outDir": "dist",
"module": "es2020",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2020",
"typeRoots": [
"node_modules/@types"
],
"baseUrl": "./",
"paths": {
"*":[
"node_modules/"
]
}
}
}
so the code to import the module is not be compile correctly because to work it should look like import { AddListeners } from './listeners.js';
listeners.jsseems to be a javascript (not typescript) file. Is this correct?node_modulesfolder and running npm install fixes this issue whenever I encounter it