Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kaiserkais's avatar

React Inertia lodash problem

hi guys when i try to build my project i get this error

'default' is not exported by node_modules/lodash/lodash.js, imported by resources/js/bootstrap.js
1: import _ from 'lodash';

how can i solve it

0 likes
7 replies
kaiserkais's avatar

@Sinnbeck im using vite

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import react from '@vitejs/plugin-react';

export default defineConfig({
    plugins: [
        laravel({
            input: 'resources/js/app.jsx',
            refresh: true,
        }),
        react(),
    ],
    optimizeDeps: {
        include: ['ckeditor5-custom-build'],
    },
    build: {
        commonjsOptions: { exclude: ['ckeditor5-custom-build'], include: [] },
    },
});
kaiserkais's avatar

@Sinnbeck this is bootstrap.js i didnt made any change im not using lodash in dom

import _ from 'lodash';
window._ = _;

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

import axios from 'axios';
window.axios = axios;

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

and this is the full error

default' is not exported by node_modules/lodash/lodash.js, imported by resources/js/bootstrap.js
file: F:/laravel/dzcod/resources/js/bootstrap.js:1:7
1: import _ from 'lodash';
          ^
2: window._ = _;
error during build:
Error: 'default' is not exported by node_modules/lodash/lodash.js, imported by resources/js/bootstrap.js
    at error (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
    at Module.error (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:12429:16)
    at Module.traceVariable (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:12788:29)
    at ModuleScope.findVariable (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:11440:39)
    at Identifier.bind (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:7439:40)
    at AssignmentExpression.bind (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
    at ExpressionStatement.bind (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:5269:23)
    at Program.bind (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:5265:73)
    at Module.bindReferences (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:12425:18)
    at Graph.sortModules (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:23024:20)
    at Graph.build (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:22902:14)
    at async file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:23689:13
    at async catchUnfinishedHookActions (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:23088:20)
    at async rollupInternal (file:///F:/laravel/dzcod/node_modules/rollup/dist/es/shared/rollup.js:23686:5)
    at async doBuild (file:///F:/laravel/dzcod/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:45815:24)
    at async build (file:///F:/laravel/dzcod/node_modules/vite/dist/node/chunks/dep-4da11a5e.js:45662:16)
    at async CAC.<anonymous> (file:///F:/laravel/dzcod/node_modules/vite/dist/node/cli.js:748:9)
Sinnbeck's avatar

@kaiserkais Not sure why it fails. But if you dont need lodash outside of you js files, just remove these two lines

import _ from 'lodash';
window._ = _;
kaiserkais's avatar

@Sinnbeck when id remove it the problem go t axios

'default' is not exported by node_modules/axios/index.js, imported by resources/js/bootstrap.js
default' is not exported by node_modules/axios/index.js, imported by resources/js/bootstrap.js

the problem made by this two lines in vite

optimizeDeps: {
        include: ['ckeditor5-custom-build'],
    },
     build: {
        commonjsOptions: { exclude: ['ckeditor5-custom-build'], include: [] },
     },
````
whene i deleted it it works perfectly

Sinnbeck's avatar

@kaiserkais Ah ok, it might make it use common js. You can try and change it from import to require

Please or to participate in this conversation.