Imagine a scenario where a library, let's name it LibraryA, relies on another library called js-yaml without type definitions. To make this work, LibraryA has a devDependency called @types/js-yam
in its package.json
. LibraryA itself compiles smoothly.
Now, in a different project where I have LibraryA installed as a devDependency, I import types from LibraryA. This triggers tsc to compile the entire project. However, tsc flags an error regarding the code in LibraryA where js-yaml is imported (import yaml from 'js-yaml'
):
error TS7016: Could not find a declaration file for module 'js-yaml'.
I checked the node_modules folder in the project, and couldn't find @types/js-yaml there. This would explain why tsc is unable to locate the typings. What perplexes me is why it wasn't installed initially when LibraryA was installed.
project
package.json
devDependencies
LibraryA
LibraryA
package.json
dependencies
"js-yaml": "^4.1.0",
devDependencies
"@types/js-yaml": "^4.0.5",
js-yaml
Therefore, the real question seems to revolve around npm and its failure to install "@types/js-yaml within the project.