我正在使用样式化组件构建一个带有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本身的react-is是一个通用的模块,因为它也可以被here签出。
既然它在node_modules/**中,那么commonjs插件不应该处理它吗?
谢谢。
发布于 2018-04-30 18:23:49
我通过使用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完成的
希望它能为你工作
发布于 2018-10-23 02:13:26
上面的修复方法对我不起作用。但是,将styled-components添加到外部变量和全局变量的rollup.config.js列表中对我来说很有效。
export default {
...
external: ['styled-components'],
...
globals: { 'styled-components': 'styled' },
};我使用的是typescript create-react-library cli,它与rollup捆绑在一起。
https://github.com/styled-components/styled-components/issues/930
发布于 2020-04-22 15:45:22
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
}),
...
]
};为我和后来加入项目的每个人解决了这个问题。
https://stackoverflow.com/questions/50080893
复制相似问题