takuma-ru / vue-swipe-modal

Modal window that can be swiped to close.(Swipeable Bottom Sheet)
https://vue-swipe-modal.takumaru.dev/
MIT License
66 stars 7 forks source link

Vue 2 require() of ES Module error #93

Closed retroriff closed 8 months ago

retroriff commented 8 months ago

With Nuxt 2 I get this error:

require() of ES Module /node_modules/@takuma-ru/vue-swipe-modal/dist/swipe-modal.umd.js from /Users/xxx/nuxt/node_modules/vue-server-renderer/build.dev.js not supported. swipe-modal.umd.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename swipe-modal.umd.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/xxx/nuxt/node_modules/@takuma-ru/vue-swipe-modal/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Any suggestion how to fix it?

takuma-ru commented 8 months ago

When used with nuxt2, this library supports only ES Modules.

You should be able to use it by importing it in the following way. import SwipeModal from "@takuma-ru/vue-swipe-modal" or const SwipeModal = await import("@takuma-ru/vue-swipe-modal")

If this did not solve the problem, please share the source code.

retroriff commented 8 months ago

Thanks for your prompt answer. Now it works