Rollup Error: 'isValidElementType' is not exported by node_modules/react-is/index.js

I resolved this by using the rollup-plugin-commonjs

and defining the export manually in the rollup config as below

export default {
  input: 'src/index.js',
  output: [
    {
      file: pkg.main,
      format: 'cjs',
      sourcemap: true
    },
    {
      file: pkg.module,
      format: 'es',
      sourcemap: true
    }
  ],
  plugins: [
    external(),
    postcss({
      modules: true
    }),
    url(),
    babel({
      exclude: 'node_modules/**'
    }),
    resolve(),
    commonjs({
      include: 'node_modules/**',
      namedExports: {
        'node_modules/react-is/index.js': ['isValidElementType']
      }
    })
  ]
}

After this everything worked fine.

and for the info, my initial setup was done through https://github.com/transitive-bullshit/react-modern-library-boilerplate

Hope it works for you


The fix above didn't work for me. However, adding styled-components to the rollup.config.js list of externals and globals worked for me.

    export default {
      ...
      external: ['styled-components'],
      ...
      globals: { 'styled-components': 'styled' },
    };

I'm using the typescript create-react-library cli, which comes bundled with rollup.

https://github.com/styled-components/styled-components/issues/930


The solution posted by FrostyDog worked for me so +1 for that, HOWEVER...

I immediately got the same error when trying to import hooks from react, I could follow the above solution and do

    export default {
      ...
      external: ['styled-components', 'react'],
      ...
    };

in rollup.config.js but I wanted a solution that handled this for all libraries, so this wasn't a recurring issue in the future.

So did this instead...

import external from "rollup-plugin-peer-deps-external";
...
export default {
    ...
    plugins: [
        external({
            includeDependencies: true
        }),
        ...
    ]
};

solved it for me and everyone adding to the project after.