我正在使用样式组件构建带有 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/