[Solved] ‘Error: Cannot find module’ from relative path in Typescript

slider Asks: ‘Error: Cannot find module’ from relative path in Typescript
My index.ts file imports a class from a bindings.d.ts file, but I’m getting Error: Cannot find module '../bindings' at run-time with no compile-time errors from TS.

My bindings.d.ts:

export class MyClass {
  sayHello(): string;

My index.ts:

import { MyClass } from "../bindings";


My tsconfig.json:

  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "moduleResolution": "node",
    "typeRoots": [
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,

My file tree:

- src
  - index.ts
- bindings.d.ts
- tsconfig.json
- node_modules
- @types

When running ts-node src/index.ts, I get the following error:

Error: Cannot find module '../bindings'
Require stack:
- /Users/slider/Desktop/myProject/src/index.ts
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/Users/slider/Desktop/myProject/src/index.ts:4:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1043:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1046:12)
    at Module.load (internal/modules/cjs/loader.js:950:32)

I’ve also tried adding "ts-node": { "files": true } but to no avail. What am I missing?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.