-
The background is we have some packages which include named imports from lodash, like: import { merge } from 'lodash'; A minimized reproduction: This project is based on the official Vue SSR example: The only thing I added was the package "foo" with a named import from lodash import { merge } from 'lodash';
// ... Then if I import "foo" to the project, it will shows:
I tried several ways of config but they all failed
Overall, I didn't find a perfect way to proceed. So ask for help. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
I don't remember the specifics, but I feel like import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
ssr: {
optimizeDeps: {
include: ["lodash"]
},
noExternal: [
'lodash',
'foo',
]
}
}) With this configuration, I'm seeing the log I'm not sure if there's any heuristic implemented to handle Btw, I think the underlying issue is that lodash's cjs build https://unpkg.com/browse/[email protected]/lodash.js is too difficult to statically analyze for NodeJs to make up named imports. One idea/workaround came to my mind for this specific case is to maybe add |
Beta Was this translation helpful? Give feedback.
I don't remember the specifics, but I feel like
lodash
needs to be pre-bundled for this case:With this configuration, I'm seeing the log
{ merge: [Function (anonymous)] }
correctly.I'm not sure if there's any heuristic implemented to handle
ssr.optimizeDeps.include
andssr.noExternal
automatically. Maybe this is a related issue?Btw, I think the underlying issue is that lodash's cjs build https://unpkg.com/browse/[email protected]/lodash.js…