Currently, I am in the process of developing an external module called @example/lib
for TypeScript that has multiple entry points. My goal is to be able to use it in the following way:
import * as lib from '@example/lib';
import * as foobar from '@example/lib/foobar';
I have been successful in creating an npm module that functions correctly by configuring my tsconfig with "target": "es5"
and "declaration": true
, as well as specifying a single source location for both the "main"
and "typings"
properties in the package.json
. This setup allows me to import @example/lib
without any issues.
The problem arises when I try to import @example/lib/foobar
. TypeScript gives an error saying it "Cannot find module @example/lib/foobar
". Interestingly, the compiled output can import this submodule successfully (once processed by webpack).
Within my @example/lib
project, the source files include:
index.js
index.d.ts
foobar.js
foobar.d.ts
In my package.json file, I have specified:
{
...
"typings": "index.d.ts"
"main": "index.js"
...
}
How can I address this issue to ensure that TypeScript remains happy and continues to perform type checking effectively in this scenario?