question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[vite]: vue-slider-component is breaking production build

See original GitHub issue

Describe the bug

Hi, I’m using vue-slider-component with vite@3, vue@2.7 and this import: import VueSlider from 'vue-slider-component'

  • Running npm run build and loading the generated bundle in the browser is throwing following error:
vue-slider-component.umd.js:724 Uncaught TypeError: Super.extend is not a function
    at componentFactory2 (vue-slider-component.umd.js:724:26)
    at vue-slider-component.umd.js:791:16
    at __decorate (vue-slider-component.umd.js:1019:95)
    at Module.fb15 (vue-slider-component.umd.js:1476:16)
    at __webpack_require__ (vue-slider-component.umd.js:30:30)
    at 091b (vue-slider-component.umd.js:94:18)
    at vue-slider-component.umd.js:95:11
    at webpackUniversalModuleDefinition (vue-slider-component.umd.js:3:20)
    at vue-slider-component.umd.js:10:1
    at vue-slider-component.umd.js:3552:2
componentFactory2 @ vue-slider-component.umd.js:724
(anonymous) @ vue-slider-component.umd.js:791
__decorate @ vue-slider-component.umd.js:1019
fb15 @ vue-slider-component.umd.js:1476
__webpack_require__ @ vue-slider-component.umd.js:30
091b @ vue-slider-component.umd.js:94
(anonymous) @ vue-slider-component.umd.js:95
webpackUniversalModuleDefinition @ vue-slider-component.umd.js:3
(anonymous) @ vue-slider-component.umd.js:10
(anonymous) @ vue-slider-component.umd.js:3552
  • Running npm run dev in development mode has no issues.

Additional context

Inspecting the Super-variable gives me this: image It looks like the extend function is under default in this case. No idea why this is different in my prod-build though.

Demo

https://stackblitz.com/edit/vue2-vite-starter-jzhxcq?file=README.md,src%2Fcomponents%2FMySliderComponent.vue

It’s starting with npm run dev in dev-mode by default in the demo, to see the working slider. To see the error in the production build and to serve the dist folder please run npm run preview. Sometimes you need to re-open/reload the preview-window, because of changing ports.

I’m using the unminified dependency here, which can be changed to test also the minified version or a different build: https://github.com/rs3d/vue2-vite-starter-slider/blob/main/vite.config.js image

Environment

  • OS & Version: Windows@11
  • Vue version: Vue@2.78
  • Component Version: vue-slider-component@3.2.20
  • Builder: Vite@3.0.4

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
rs3dcommented, Aug 3, 2022

@NightCatSama Thank you for testing it out. I’ve investigated it a bit further and it seems like vite > rollup for prod and vite > esbuild for dev is treating the Vue-Import differently.

Using this option in vite.config.js helped to change Super.default.extend to Super.extend:

export default defineConfig({
  // ...{ otherOptions }
  build: {
    commonjsOptions: {
      /**
       * Setting to make prod-build working with vue-slider-component
       **/
       requireReturnsDefault: true,
    },
  },
})

https://github.com/rollup/plugins/tree/master/packages/commonjs#requirereturnsdefault I’m not sure, but this might then be an issue of vue in combination with rollup…

I’ve also tried an async import, which also has a difference how the import is treated. This code works for me in dev/prod:

import { Component, Vue } from 'vue-property-decorator'
@Component({
  components: {
    VueSlider: () =>
      import('vue-slider-component').then((module) => {
        return module?.default
      }),
  },
})

In prod module is defined (.default not) and in dev module.default is defined … Probably there is also a way somewhere in https://esbuild.github.io/ to align this, but I think it’s okayish to use it like this.

Maybe this can be solved also by some export flags in the vue-slider-component.umd.js?

Updated working demo: https://stackblitz.com/edit/vue2-vite-starter-6qq9x7?file=vite.config.js

4reactions
schyffelcommented, Nov 18, 2022

Based on the response from @rs3d, setting this in vite.config.ts did it for my build:

Thanks!

export default defineConfig({
  build: {
    commonjsOptions: {
      requireReturnsDefault: true
    }
  },
  // ...
})

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue-slider-component - npm
A highly customized slider component. Latest version: 3.2.24, last published: 20 days ago. Start using vue-slider-component in your project ...
Read more >
Slider component is breaking on API call in Vue Js
Hi Developers,. I am using splidejs for the vue slider component. I don't think issue with splidejs. But there is an issue described...
Read more >
Laravel 9 (with Vite) and Vue 3 integration [For Metronic ...
We just updated vite.config.js to fix some issues for the production build. Could you please rerun the build command with the updated config?...
Read more >
Upgrade Guide - Quasar Framework
You'll need to adapt to the breaking changes of the new versions of Vue 3, Vue Router 4, Vuex 4, Vue-i18n 9 and...
Read more >
vite+vue2-vue-slider-component - CodeSandbox
Templatevue2-vite; Environmentnode. Files. public. src .gitignore. README.md. index.html. package-lock.json. package.json. vite.config.js. Dependencies. vue.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found