I've developed a Typescript package with the following file structure:
package.json
src/
index.ts
common/
index.ts
sub/
index.ts
My goal is to import certain modules from the package like this:
import {...} from '<package>';
import {...} from '<package>/sub';
However, I do not want to allow importing from <package>/common
.
Is there a way to achieve this without using custom declaration files?
The configuration in my package.json
is inspired by this:
"exports": {
".": "./dist/index.js",
"./common": "./dist/common/index.js"
},
"typesVersions": {
"*": {
"common": ["declarations/common/index.d.ts"]
}
}
While this setup works fine for Typescript, I encounter an issue during the build process when attempting to access the module in JS:
Module not found: Error: Can't resolve '<package>/sub' in '...'