Are you using laravel mix or vite ?
Oct 20, 2022
7
Level 2
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
Level 102
Level 2
@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: [] },
},
});
Level 102
@kaiserkais And your bootstrap.js ? Are you using lodash in your dom ?
Level 2
@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)
Level 102
@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._ = _;
Level 2
@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
Level 102
@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.