patterntypescriptCritical
Could not find a declaration file for module 'module-name'. '/path/to/module-name.js' implicitly has an 'any' type
Viewed 0 times
hasdeclarationmodulecouldnameanyimplicitlyfindforfile
Problem
I read how TypeScript module resolution works.
I have the following repository: @ts-stack/di.
After compiling the directory structure is as follows:
In my package.json I wrote
In Node.js everything works fine, but TypeScript:
Could not find a declaration file for module '@ts-stack/di'. '/path/to/node_modules/@ts-stack/di/dist/index.js' implicitly has an 'any' type.
And yet, if I import as follows, then everything works:
What am I doing wrong?
I have the following repository: @ts-stack/di.
After compiling the directory structure is as follows:
├── 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.jsonIn my package.json I wrote
"main": "dist/index.js".In Node.js everything works fine, but TypeScript:
import {Injector} from '@ts-stack/di';Could not find a declaration file for module '@ts-stack/di'. '/path/to/node_modules/@ts-stack/di/dist/index.js' implicitly has an 'any' type.
And yet, if I import as follows, then everything works:
import {Injector} from '/path/to/node_modules/@ts-stack/di/dist/index.js';What am I doing wrong?
Solution
For the situation where you are installing your own npm package
If you're using a third party package, see my answer below.
Remove
Also add
The folder
If you're using a third party package, see my answer below.
Remove
.js from "main": "dist/index.js" in package.json."main": "dist/index",
Also add
types in package.json per the TypeScript docs:"main": "dist/index",
"types": "dist/index",
The folder
dist is where the TS compiler stores your module's files.Context
Stack Overflow Q#41292559, score: 215
Revisions (0)
No revisions yet.