Reactjs 汇总错误:';isValidElementType';不是由节点_modules/react is/index.js导出的
我正在使用样式化组件构建一个具有汇总功能的捆绑包 我的rollup.config.js看起来像:Reactjs 汇总错误:';isValidElementType';不是由节点_modules/react is/index.js导出的,reactjs,rollup,styled-components,Reactjs,Rollup,Styled Components,我正在使用样式化组件构建一个具有汇总功能的捆绑包 我的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: 'd
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';
检查节点_模块本身是一个常见的JS模块,因为它也可以被检出
commonjs插件不应该处理它吗,因为它位于node_modules/**内
谢谢。我通过使用
汇总插件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']
}
})
]
}
在这之后,一切都很顺利
至于信息,我的初始设置是通过
希望它对你有用上面的修复对我不起作用。然而,将
样式化组件添加到rollup.config.js
外部和全局列表中对我来说很有效
export default {
...
external: ['styled-components'],
...
globals: { 'styled-components': 'styled' },
};
我使用的是typescript cli,它与rollup捆绑在一起
FrostyDog发布的解决方案对我有效,因此+1,但是
在尝试从react
导入钩子时,我立即遇到了相同的错误,我可以按照上面的解决方案进行操作
export default {
...
external: ['styled-components', 'react'],
...
};
在rollup.config.js中
但是我想要一个解决方案来处理所有库的这个问题,所以这在将来不是一个反复出现的问题
所以我改成了
import external from "rollup-plugin-peer-deps-external";
...
export default {
...
plugins: [
external({
includeDependencies: true
}),
...
]
};
为我和之后加入项目的所有人解决了这个问题。为我工作。谢谢虽然我不得不在数组中使用['isValidElementType','isContextConsumer'],但这对我来说是有效的。只是为了更新,它看起来像globals现在是输出的一部分。所以现在应该是:`。。。外部:['styled-components']。。。输出:{globals:{'styled components':'styled'}}`create react library
的另一个更新-因为它使用(一个分支)微绑定通过命令行构建命令传递--外部样式化组件