Expected Behavior
"ts-node test.ts" should print "hello"
Actual Behavior
Error: Cannot find module
I'm not sure where is wrong. tsc works well but ts-node can't resolve the module "testModule" which is declared with "declare module" in a d.ts.
Steps to reproduce the problem
- ts-node 9.1.1; node 14.15.5;tsc 4.2.3
- at same directory, I have three files test.ts, testModule.d.ts, testModule.js
function testMethod(){
console.log("hello")
}
module.exports={testMethod};`
declare module "testModule" {
export function testMethod():void;
};
import * as t from "testModule"; t.testMethod();
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"allowJs": true,
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true,
"outDir": "./out",
"moduleResolution": "node",
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {"testModule":["testModule.js"]},
"typeRoots": ["./node_modules/@types"],
"traceResolution":true
},
}
- then, "ts-node test.ts" will give error
Error: Cannot find module 'testModule'
Require stack:
- /Users/daixuan/mine/mycode/learnTS/tryts/test.ts
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (/Users/daixuan/mine/mycode/learnTS/tryts/test.ts:1:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Module.m._compile (/Users/daixuan/mine/mycode/opencvjs/emsdk/node/14.15.5_64bit/lib/node_modules/ts-node/src/index.ts:1056:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Object.require.extensions. [as .ts] (/Users/daixuan/mine/mycode/opencvjs/emsdk/node/14.15.5_64bit/lib/node_modules/ts-node/src/index.ts:1059:12)
at Module.load (internal/modules/cjs/loader.js:928:32)
Minimal reproduction
Specifications
- ts-node version:
- node version:
- TypeScript version:
- tsconfig.json, if you're using one:
- Operating system and version:
- If Windows, are you using WSL or WSL2?:
Expected Behavior
"ts-node test.ts" should print "hello"
Actual Behavior
Error: Cannot find module
I'm not sure where is wrong. tsc works well but ts-node can't resolve the module "testModule" which is declared with "declare module" in a d.ts.
Steps to reproduce the problem
Minimal reproduction
Specifications