Vite Rollup build failed with error by some exports

47 Views Asked by At

Im trying to move from CRA+CRACO to Vite. All works fine in dev-mode locally, but when im trying to build it fails with errors like:

RollupError: node_modules/redux-form/es/structure/plain/deepEqual.js (1:7): 
"default" is not exported by "node_modules/lodash/isNil.js", 
imported by "node_modules/redux-form/es/structure/plain/deepEqual.js".

Here is my Vite config:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [react()],

    define: {
        global: 'window',
        module: 'window',
    },

    resolve: {
        alias: {
            '../../theme.config': path.resolve(__dirname, './src/semantic-ui/theme.config'),
        },
    },

    css: {
        preprocessorOptions: {
            less: {
                math: 'always',
                javascriptEnabled: true,
            },
        },
    },

    build: {
        rollupOptions: {
            // external: [
            //  'lodash/isNil',
            //  'invariant',
            //  'is-promise',
            //  'keyboard-key',
            //  'shallowequal',
            //  'react-fast-compare',
            //  'warning',
            // ],
        },
    },
});

As you see in config, i tried to configure Rollup build options, and it builds fine, BUT when I open build with serve -s dist it crashes with Uncaught TypeError: Failed to resolve module specifier "lodash/isNil". Relative references must start with either "/", "./", or "../".

0

There are 0 best solutions below