小编典典

汇总错误:node_modules / react-is / index.js未导出“ isValidElementType”

reactjs

我正在使用样式组件与rollUp建立捆绑。

我的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本身的反应-
是一个commonjs模块,因为它也可以在此处检出。

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

谢谢。


阅读 1383

收藏
2020-07-22

共1个答案

小编典典

我通过使用 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完成的

希望对你有帮助

2020-07-22