reactjs - 汇总错误 : 'isValidElementType' is not exported by node_modules/react-is/index. js

标签 reactjs rollup styled-components

我正在使用样式组件构建带有 rollUp 的 bundle 。

我的 rollup.config.js 看起来像:

import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs'
  },
  external: [
    'react',
    'react-proptypes'
  ],
  plugins: [
    resolve({
      extensions: [ '.js', '.json', '.jsx' ]
    }),
    commonjs({
      include: 'node_modules/**'
    }),
    babel({
      exclude: 'node_modules/**'
    })
  ]
}

我收到了

[!] Error: 'isValidElementType' is not exported by node_modules/react-is/index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
node_modules/styled-components/dist/styled-components.es.js (7:9)
5: import stream from 'stream';
6: import PropTypes from 'prop-types';
7: import { isValidElementType } from 'react-is';
            ^
8: import hoistStatics from 'hoist-non-react-statics';

检查node_modules本身react-is是一个commonjs模块,因为它可以被 checkout here也是如此。

commonjs 插件不应该处理它吗,因为它位于 node_modules/** 内部?

谢谢。

最佳答案

我通过使用rollup-plugin-commonjs解决了这个问题

并在汇总配置中手动定义导出,如下所示

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']
      }
    })
  ]
}

此后一切正常。

关于信息,我的初始设置是通过 https://github.com/transitive-bullshit/react-modern-library-boilerplate 完成的

希望它对你有用

关于reactjs - 汇总错误 : 'isValidElementType' is not exported by node_modules/react-is/index. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50080893/

相关文章:

tsql - 从 sql 汇总中的小计/总计中删除空值

css - react-jss 不缓存 css 类

css 滚动捕捉不适用于 React 应用程序中的 div

cors - Svelte API 代理 cors

javascript - React功能组件: can we setState on form load event

reactjs - 您为选择组件提供了超出范围的值 `undefined`

css - 为新的 Web 组件更新 UI Framework CSS

browserify - 相当于 "browserify -r"的汇总

css - 使用样式组件,如何定位组件的子类?

javascript - 在 React Redux 应用程序中,我在哪里从服务器获取初始数据?