DEV Community

Discussion on: How to Create and Publish a React Component Library

Collapse
 
wesleyjanse profile image
Wesley Janse

Great post,

Got a small issue, running the tests though, You mentioned something
about not adding React-Dom to the library since that would deny the purpose of building a 'standalone' component library, if I remember correctly.

Now when I try to run 'yarn test' I'm getting the following error.

Cannot find module 'react-dom' from 'node_modules/@testing-library/react/dist/pure.js'

This is fixed when I add React-Dom to the project.

Do you see any way around this?

Collapse
 
alexeagleson profile image
Alex Eagleson

In the "Adding Tests" section there is an instruction for editing your jest config to use jsdom instead of React DOM which is aimed to eliminate the need for that dependency, did you include that in your config?

Collapse
 
wesleyjanse profile image
Wesley Janse

Yes I have that included, I have just added React-Dom as a peer dep, as a workaround. It is accessing the config file correctly though, just always wants to go back to ReactDom, but the workaround works, and since we need it anyway for storybook it's fine.

Thanks again for the blog!

Collapse
 
darkmattermatters profile image
SuperSegfault • Edited

I also have the same issue, only fixed by installing react-dom. It's probably worth mentionning that I did not include the Storybook part in my library and I did not publish on npm. But apart from that it's the same config files.
Also, moving react to peerDependencies does not work with Jest as he seems to need them in order to run the tests (because of the import in Button.test.tsx). Without Jest the packaging seems to work though.

Some comments have been hidden by the post's author - find out more