-
Notifications
You must be signed in to change notification settings - Fork 126
[!] Error: 'default' is not exported by ../../node_modules/prop-types/index.js #361
Comments
@xianshannan Do you have monorepo? |
Try |
@TrySound I have monorepo. // rollup.config.js
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
export default {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'umd',
name: 'umdName',
indent: false,
sourcemap: false,
},
plugins: [
nodeResolve(),
commonjs({
namedExports: {
'node_modules/react-js/index.js': ['isValidElementType'],
},
include: [
/node_modules\/prop-types/,
/node_modules\/hoist-non-react-statics/,
/node_modules\/invariant/,
/node_modules\/react-is/,
/node_modules\/warning/,
],
}),
],
}; |
I use names which I import from
|
@TrySound Thanks, it did work. |
@TrySound Thanks for this! Finally realized my node modules being |
I wonder if there should be a note in the docs about monorepos? Most tools play nice with different |
@NathanielHill I'm having this exact same issue with a monorepo. Came to rollup for a react component library and a note like that would be incredibly helpful. |
@josefaidt Did you fix your problem? |
I created a pull request to update the docs with a note: #372 |
@NathanielHill No I have not. Using the |
@josefaidt You also need to be careful about whether |
Ah that did it. Didn't think about the transpilation at first. I had to also add all of my dependencies to export default {
input: './src/index.js',
output: {
file: './build/bundle.js',
name: 'SomeModule',
format: 'iife',
sourcemap: 'inline',
},
plugins: [
babel({
plugins: babelPlugins,
presets: babelPresets,
exclude: /node_modules/,
}),
url(),
postCss({ modules: true }),
nodeResolve(),
cjs({ include: /node_modules/ }),
],
external: ['react', 'react-dom', 'prop-types', 'styled-components'],
} |
🎉 Exactly! There's a plugin to generate the externals automatically from Would be nice if that worked. |
Yes, thank you for your timely assistance! Thankfully this will be a relatively small library in terms of packages used, but I agree it would be nice to do it automatically. |
+1 namedExports always is not work, I have tried all the above methods. |
+1 , is this a bug ? the rollup-plugin-commonjs doc about namedExports not useful? |
To go with #361 (comment) and anyone else reading this (and maybe working in a monorepo), to fix commonjs({
// https://github.com/rollup/rollup-plugin-commonjs#usage-in-monorepo
include: /node_modules/,
namedExports: {
// node_modules/prop-types/factoryWithTypeCheckers.js#L115
'prop-types': [
'array',
'bool',
'func',
'number',
'object',
'string',
'symbol',
'any',
'arrayOf',
'element',
'elementType',
'instanceOf',
'node',
'objectOf',
'oneOf',
'oneOfType',
'shape',
'exact',
],
},
}), Alternatively, and against the suggestions of |
I've been having an absolute inconsistent behaviour with the commonjs({
include: [
"node_modules",
"node_modules/**",
"node_modules/**/*",
namedExports: { ... },
}), Don't put all three, just use the one that makes |
@AntonioRedondo RegEx is more universal here commonjs({
include: /node_modules/,
namedExports: { ... }
}) |
rollup config
When running
rollup -c
,it will throw the error.I have been looking for this problem for a while, but there is no solution.
But when using commonjs without any options,it wok fine.
The text was updated successfully, but these errors were encountered: