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

风格不统一 提交于 2019-12-03 10:58:05

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!