I am in the process of developing a package for npm and I would like it to be imported in the following manner:
import myPackage from 'my-package';
import { subFunction1, subFunction2 } from 'my-package/subfunctions';
Upon trying to utilize the package I have created, the main file loads without any issues but I encounter the following error when it comes to the subfolder:
Cannot find module 'my-package/subfunctions'
The current structure of the folder that is set to be published on npm is as follows:
index.js
index.d.ts
subfunctions/
sub-function-1.js
sub-function-1.d.ts
sub-function-2.js
sub-function-2.d.ts
index.js
index.d.ts
Furthermore, the type declarations in the package.json file are configured as:
"types": [
"./dist/index.d.ts",
"./dist/subfunctions/index.d.ts",
],
Below are the contents of the files index.d.ts (1) and subfunctions/index.d.ts (2):
(1)
import myCode from './lib/my-code';
export default myCode;
(2)
export { subFunction1 } from './sub-function-1';
export { subFunction2 } from './sub-function-2';
Is there a way for me to successfully import from this subfolder?