Skip to content

SSR: named imports from lodash #16005

Answered by hi-ogawa
Jinjiang asked this question in Q&A
Feb 22, 2024 · 1 comments · 9 replies
Discussion options

You must be logged in to vote

I don't remember the specifics, but I feel like lodash needs to be pre-bundled for this case:

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 { merge: [Function (anonymous)] } correctly.

I'm not sure if there's any heuristic implemented to handle ssr.optimizeDeps.include and ssr.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

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@hi-ogawa
Comment options

@Jinjiang
Comment options

@hi-ogawa
Comment options

@hi-ogawa
Comment options

@Jinjiang
Comment options

Answer selected by Jinjiang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants