lukaszflorczak / vue-agile

🎠 A carousel component for Vue.js
https://lukaszflorczak.github.io/vue-agile/
MIT License
1.49k stars 167 forks source link

Vue & Vite: lodash modules have no default #237

Open HerrHansen opened 2 years ago

HerrHansen commented 2 years ago

Setup vue: "^3.2.25" with vite

  1. I installed "vue-agile": "^2.0.0" via npm i vue-agile
  2. I initialized it in main.js
  3. I get fatal error in console, app won't load

Error in console

settings.js:5 Uncaught SyntaxError: The requested module '/node_modules/lodash.orderby/index.js?v=e65522c4' does not provide an export named 'default'

Initialization in main.js

//main.js
... other imports
import VueAgile from 'vue-agile';

const app = createApp({
  setup() {
    provide(DefaultApolloClient, apolloClient);
  },
  render: () => h(App),
});

app.use(VueAgile);

Expected behavior A running app.

Screenshots If applicable, add screenshots to help explain your problem.

Bildschirmfoto 2022-03-04 um 10 16 37

Solution It is a vite issue.

Found a solution here: https://github.com/nuxt/vite/issues/56

// vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  server: {
    port: 3001,
  },
  optimizeDeps: {
    include: [
      'lodash.throttle' // if it is inlcuded here, error is gone 🐓
    ]
  },
  ...
});
fritzdultimate commented 2 years ago

It doesn't solve my problem, still showing the errors above

dllsystem commented 2 years ago

this way it worked for me

optimizeDeps: { include: [ 'lodash.throttle', 'lodash.orderby' ] },

semer-11 commented 2 years ago

this way it worked for me

optimizeDeps: { include: [ 'lodash.throttle', 'lodash.orderby' ] },

It did solve the problem