cipami / nuxt-lodash

Lodash module for Nuxt
MIT License
104 stars 11 forks source link

error when using chain syntax in static site (ssr: false) #42

Closed lpfy closed 1 year ago

lpfy commented 1 year ago

Hi there,

Just wondering does this plug-in support chain syntax? e.g. useChain(myArray).find({id: 2}).get("val").value()

I am facing a very strange issue, the code running fine when in Dev mode but not in production. Once SPA site generated, it doesn't like chain syntax. The error pops up as below: TypeError: (intermediate value)(intermediate value)(intermediate value)(...).find is not a function

Nuxt3 example code - example.vue

<template>
  <div>
    <p>{{ useChain(myArray).find({id: 2}).get("val").value() }}</p>
    <p>{{ filtered }}</p>
  </div>
</template>

<script setup lang="ts">
const myArray = ref([{id:1, val:"test1"},{id:2, val:"test2"}]),
      filtered = computed( () => useChain(myArray.value).find({id: 1}).get("val").value() );

</script>

Hopefully, someone can guide me to solve this issue, maybe a config problem??

Cheers

slyedoc commented 1 year ago

Have the same issue, ssr: false and works fine in Dev, production cant find chain.

cipami commented 1 year ago

Not possible as chain needs almost all lodash functions and they are tree shaken on build. You can try flow solution as mentioned here https://stackoverflow.com/a/45464732/10745364

ausir0726 commented 1 year ago

@cipami

Perhaps it is possible to add a warning when using useChain. Please note that useChain cannot be used in a production environment (bundle missing).

If not warned in this way, we would realize, after completing a substantial amount of code, that everything is a mess only when we are waiting to release the Nuxt build version.

katerlouis commented 2 days ago

@cipami

Perhaps it is possible to add a warning when using useChain. Please note that useChain cannot be used in a production environment (bundle missing).

If not warned in this way, we would realize, after completing a substantial amount of code, that everything is a mess only when we are waiting to release the Nuxt build version.

I'm in that exact situation right now and could've adapted to that if I had known before

@cipami is there no way to tell the app to keep the "used sub functions" of chain? I only use 5-6 functions (uniq, reject, pick, omit, filter, map)