I’m developing a Node.js app (MyApp) and a Node.js module (MyTools) simultaneously on a Windows 2019 server with node v18.16.0.
You can find the full code on GitHub: https://github.com/zero2411/myapp
I’m using npm link to add MyTools to MyApp, but I’m encountering an error on line 1 in myapp.ts:
Cannot find module 'mytools' or its corresponding type declarations.ts(2307)
Directory Structure
myapp/
├── node_modules/
│ └── mytools/ (linked)
│ ├── mytools.d.ts
│ ├── mytools.d.ts.map
│ ├── mytools.js
│ ├── mytools.ts
│ ├── package.json
│ └── tsconfig.json
├── myapp.ts
├── myapp.js
├── package.json
├── package-lock.json
└── tsconfig.json
MyTools Setup
Created the folder mytools.
Initialized the module:
> npm init -y
> tsc --init
Updated tsconfig.json:
"declaration": true,
"declarationMap": true
Created mytools.ts:
export class MyTools {
// Class implementation
}
Transpiled TypeScript to JavaScript:
> tsc
Linked the module globally:
> npm link
MyApp Setup
Created the folder myapp
Initialized the app:
> npm init -y
> tsc --init
Linked mytools to myapp:
> npm link mytools
This added mytools to node_modules as expected.
Created myapp.ts and imported MyTools:
import { MyTools } from "mytools";
Problem
Cannot find module 'mytools' or its corresponding type declarations.ts(2307)
Additional Information
Both MyApp and MyTools have their tsconfig.json files configured to handle TypeScript.
The node_modules directory in MyApp correctly includes mytools.
I’ve tried several solutions, but the error persists.
What am I missing or doing wrong?