After diving into the inner workings of TypeScript module resolution, I stumbled upon an issue.
Within my repository @ts-stack/di, the directory structure post-compilation looks like this:
├── dist
│ ├── annotations.d.ts
│ ├── annotations.js
│ ├── index.d.ts
│ ├── index.js
│ ├── injector.d.ts
│ ├── injector.js
│ ├── profiler.d.ts
│ ├── profiler.js
│ ├── providers.d.ts
│ ├── providers.js
│ ├── util.d.ts
│ └── util.js
├── LICENSE
├── package.json
├── README.md
├── src
│ ├── annotations.ts
│ ├── index.ts
│ ├── injector.ts
│ ├── profiler.ts
│ ├── providers.ts
│ └── util.ts
└── tsconfig.json
In my package.json, I designated "main": "dist/index.js"
.
While everything runs smoothly in Node.js, TypeScript throws an error:
import {Injector} from '@ts-stack/di';
An error is triggered stating that a declaration file for module '@ts-stack/di' cannot be found. The file '/path/to/node_modules/@ts-stack/di/dist/index.js' seems to have an undefined type.
However, switching to a different import statement resolves the issue:
import {Injector} from '/path/to/node_modules/@ts-stack/di/dist/index.js';
What could be the cause of this problem?