DEV Community

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

Collapse
 
samiulhsohan profile image
Samiul H. Sohan • Edited

Great tutorial, @alexeagleson !

I am facing a problem. Whenever I'm using things like useState in the library and then importing in my Next.js project, it's giving me error.

TypeError: Cannot read properties of null (reading 'useState')

error

And if I move react inside the peerDependencies, it shows this error:

error2

Collapse
 
lsjesus profile image
Lucas Silva de Jesus

Hi @samiulhsohan!

I'm facing the same problem in my react aplication. Did u solved it??

Collapse
 
matthiasnannt profile image
Matthias Nannt

Hi @samiulhsohan
I faced the same problem and found a solution. This is what causes the error:
blog.maximeheckel.com/posts/duplic...

And this is my next.config.js that solves the issue:

var path = require("path");

module.exports = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    config.resolve.alias["react"] = path.resolve("./node_modules/react");
    return config;
  },
};
Enter fullscreen mode Exit fullscreen mode

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