Next.js Discord

Discord Forum

NextJS in a component library

Unanswered
Jindo posted this in #help-forum
Open in Discord
JindoOP
When I install NextJS into a component library to take advantage of next/link and next/image, when it is consumed by my main NextJS apps, it crashes with Error: EMFILE: too many open files,

The project is structured such that there are 3 projects, 2 are standalone NextJS apps, which consume the component library.
I installed NextJS into the component library so that I was able to use the next/image and next/link components in order to build reusable components that will be used across the 2 other projects.
The component library is installed using file:../ui-library - as an example - inside the 2 NextJS apps.
Once I uninstalled NextJS from the ui-library it loads as normal.
Everything in the ui-library is installed as a peer dependency.
I also added the config.resolve.alias change as follows, as this was primarily to fix the issue with react-hooks, but added NextJS here so that it was also able to be consumed by the ui-library

  webpack: (config) => {
    const paths = {
      react: path.join(__dirname, 'node_modules/react'),
      'react-dom': path.join(__dirname, 'node_modules/react-dom'),
      next: path.join(__dirname, 'node_modules/next'),
    };
    config.resolve = {
      ...config.resolve,
      alias: {
        ...config.resolve.alias,
        ...paths,
      },
    };
    return config;
  },


Any help or advice would be appreciated

0 Replies