I am currently in the process of developing a React component library using Typescript that I want to import into another Typescript project. Specifically, I want to import an Analytics chart library into a storybook for demonstration and testing purposes.
For this endeavor, I have included the following dependencies for the library:
- "typescript": "^3.1.6"
- "webpack": "^4.15.1"
- "babel-loader": "^8.0.4"
- "ts-loader": "^5.3.0"
- "@babel/core": "^7.1.5",
- "@babel/runtime": "^7.1.5",
- "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
- "@babel/plugin-syntax-dynamic-import": "^7.0.0",
- "@babel/preset-env": "^7.1.5",
- and many more...
In addition, I've added these extra dependencies for the storybook:
- "@storybook/react": "^4.0.4"
- all of the aforementioned dependencies
- and many more...
Furthermore, here are the settings in the tsconfig.json file of my library:
- "module": "esnext",
- "moduleResolution": "node",
- "target": "es5" (this has been intentionally set)
- etc.
When Webpack generates the d.ts file, it contains various declarations including the following:
declare module 'mylibrary' {
...
}
Finally, the libraryTarget specified is UMD.
However, when attempting to import the library in the storybook like this:
import * as Analytics from "mylibrary";
and then running a
console.log(Analytics)
The console displays:
Module
Symbol(Symbol.toStringTag): "Module"
__esModule: true
__proto__: Object
This output is not what I expected, as ideally I would like to see an Object that I can interact with as defined in the d.ts file.
It seems there may be a fundamental error or misunderstanding on my part regarding exports and imports. Any guidance on how to rectify this issue would be greatly appreciated. Feel free to ask if further details are required.
Thank you,
Walter
EDIT: Minimal project setup
- In the "analytics" folder, run "yarn install && yarn run dist"
- Navigate to the "storybook" folder and run "yarn install && yarn start-storybook"
- Open a browser and go to localhost:6006
- Check the developer console for messages starting with "There you go!"
- I expect to see an Object containing all the Analytics factories instead of a Module or undefined...