unplugin-auto-import icon indicating copy to clipboard operation
unplugin-auto-import copied to clipboard

If imports receives a two-dimensional array object format implemented as a function, it will report a type error.

Open eevho opened this issue 1 year ago • 1 comments

Describe the bug

CleanShot 2024-04-16 at 17 23 58@2x

code:

/src/plugins/lodash
import lodash from 'lodash'

export function lodashImports() {
  const exports = Object.keys(lodash).map(v => [v, `use${lodash.upperFirst(v)}`])

  return {
    lodash: exports,
  }
}

/vite.config.ts
import { lodashImports } from './src/plugins/lodash'
...
export default defineConfig({
  plugins: [
    AutoImport({ imports: [lodashImports()] })
  ]
})

CleanShot 2024-04-16 at 17 30 44@2x

Reproduction

https://stackblitz.com/edit/vitejs-vite-bljbqc?file=vite.config.ts

System Info

System:
    OS: macOS 14.0
    CPU: (8) arm64 Apple M1 Pro
    Memory: 284.13 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.0 - ~/.volta/tools/image/node/18.19.0/bin/node
    npm: 10.2.3 - ~/.volta/tools/image/node/18.19.0/bin/npm
    pnpm: 8.10.2 - ~/.volta/tools/image/pnpm/8.10.2/bin/pnpm
    bun: 1.0.11 - ~/.bun/bin/bun
  Browsers:
    Chrome: 123.0.6312.124
    Safari: 17.0

Used Package Manager

pnpm

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the Contributing Guide.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • [X] The provided reproduction is a minimal reproducible of the bug.

eevho avatar Apr 16 '24 09:04 eevho

It seems like this might be the expected behavior. Refer to the type definition.

You can try using it like this:

export function lodashImports() {
 const exports = Object.keys(lodash).map(v => `use${lodash.upperFirst(v)}`)

 return {
 	lodash: exports,
 }
}

ilyaliao avatar Jul 20 '25 08:07 ilyaliao