#build config ? error building server bundle with lodash

1 messages · Page 1 of 1 (latest)

gaunt kayak
#

I'm getting this error in my server-bundle, I tried a few plugins and different settings but can't get it to work.

`file:///home/apps/gunners/dist/server/entry-server.js:4
import { isArray, findIndex, filter as filter$1, uniq, debounce as debounce$2, extend as extend$1, map, intersection, without, each, maxBy, sortBy, uniqBy, groupBy, cloneDeep, difference } from 'lodash-es';
^^^^^^^^^
SyntaxError: Named export 'cloneDeep' not found. The requested module 'lodash-es' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'lodash-es';
const { isArray, findIndex, filter: filter$1, uniq, debounce: debounce$2, extend: extend$1, map, intersection, without, each, maxBy, sortBy, uniqBy, groupBy, cloneDeep, difference } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

`

gaunt kayak
#

this is my vite.config.js
export default defineConfig(({ command, ssrBuild }) => ({ base, resolve: { alias: { "@": resolve(__dirname, "src") }, }, server: { fs: { // Allow serving files from one level up to the project root allow: [ // search up for workspace root searchForWorkspaceRoot(process.cwd()), // your custom rules '../../' ], }, }, plugins: [ vuePlugin( { template: { transformAssetUrls: { includeAbsolute: false } }}), vueJsx(), optimizeLodashImports(), viteCommonjs() ], build: { target: 'esnext', rollupOptions: { input: { app: './src/index.template.html', // default }, external: ["lodash-es"], }, }, ssr: { noExternal: [ // this package has uncompiled .vue files '@vitejs/test-example-external-component','vue-multiselect','vuedraggable','vue-datepicker','lodash-es' ], }, optimizeDeps: { exclude: ['@vitejs/test-example-external-component'], force:true }, }))