rollup / rollup-plugin-commonjs

This module has moved and is now available at @rollup/plugin-commonjs / https://github.com/rollup/plugins/blob/master/packages/commonjs
MIT License
501 stars 126 forks source link

[!] Error: 'use Callback' is not exported by node_modules\react\index.js #425

Closed wildfrontend closed 4 years ago

wildfrontend commented 4 years ago

this is my config code

   commonjs({
            include: 'node_modules/**',
            namedExports: {
                'node_modules/react/index.js': [
                    'Component',
                    'PureComponent',
                    'Fragment',
                    'Children',
                    'createElement',
                    'useContext',
                    'useEffect',
                    'useLayoutEffect',
                    'useMemo',
                    'useReducer',
                    'useRef',
                    'useState',
                ],
                'node_modules/react-dom/index.js': ['unstable_batchedUpdates'],
                'node_modules/react-is/index.js': [
                    'isContextConsumer',
                    'isValidElementType',
                ],
            },
        }),

if i add useCallback in common(namedExports:{ 'node_modules/react/index.js'}) rollup can build success but it will show useEffect is not defined

so my problem how do i exported useCallback

TrySound commented 4 years ago

The problem is that react does not provide any detectable exports in commonjs entry point. Here's the solution. https://github.com/rollup/rollup-plugin-commonjs/issues/290#issuecomment-537683484