汇总错误:node_modules/react-is/index.js 未导出“isValidElementType" [英] Rollup Error: 'isValidElementType' is not exported by node_modules/react-is/index.js
问题描述
我正在使用 styled-components 构建一个带有 rollUp 的包.
I'm building a bundle with rollUp using styled-components.
我的 rollup.config.js 看起来像:
My rollup.config.js looks like:
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 模块,因为它可以检查 这里也是.
Checking on the node_modules itself react-is is a commonjs module as it can be checked out here as well.
commonjs 插件不应该处理它,因为它在 node_modules/** 内部吗?
Shouldn't the commonjs plugin take care of it since it is inside node_modules/** ?
谢谢.
推荐答案
我使用 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']
}
})
]
}
此后一切正常.
关于信息,我的初始设置是通过 https://github.com/transitive-bullshit/react-modern-library-boilerplate
and for the info, my initial setup was done through https://github.com/transitive-bullshit/react-modern-library-boilerplate
希望对你有用
这篇关于汇总错误:node_modules/react-is/index.js 未导出“isValidElementType"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!