-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require() of ES modules is not supported (Quasar v2) #85
Comments
I have a similar problem with a third party library: aws-amplify/ui-vue:
When I render the app with @freddy38510: Is it possible to tell your extension to "leave out" one specific page or even component, or explicitly tell the extension which pages to render and which ones should stay i spa mode? |
@kostia7alania this here: might help you. It explicitly puts the component on the client. Maybe that will help webpack circumventing the issue? |
You are right, the compilation with webpack itself has no errors. But even with SSR mode when you start the web-server you got the error about ES module which is not supported. This is because since version 7 Swiper is a pure ESM package. You can downgrade to v6 or async import the components. // your SFC component
import { defineComponent, defineAsyncComponent } from 'vue';
export default defineComponent({
components: {
swiper: defineAsyncComponent(async () => {
const { Swiper } = await import('swiper/vue');
return Swiper;
}),
swiperSlide: defineAsyncComponent(async () => {
const { SwiperSlide } = await import('swiper/vue');
return SwiperSlide;
}),
}); Using Quasar boot files can do the trick too if you want to register globally some components. Running it on client-side only: // boot/swiper.js file
import { Swiper, SwiperSlide } from 'swiper/vue';
export default ({ app }) => {
app.component('swiper', Swiper);
app.component('swiper-slide', SwiperSlide);
};
// quasar.conf.js file
module.exports = configure((ctx) => ({
boot: [
{
server: false, // run on client-side only!
path: 'swiper', // references /src/boot/<name>.js
},
],
}); Or on client-side and server-side: // boot/swiper.js file
import { defineAsyncComponent } from 'vue';
export default ({ app }) => {
app.component('swiper', defineAsyncComponent(async () => {
const { Swiper } = await import('swiper/vue');
return Swiper;
}));
app.component('swiper-slide', defineAsyncComponent(async () => {
const { SwiperSlide } = await import('swiper/vue');
return SwiperSlide;
}));
};
// quasar.conf.js file
module.exports = configure((ctx) => ({
boot: ['swiper'],
}); If after all you've got some hydration errors at client-side you can wrap the components in the Quasar
|
Found a better way to handle this. Just transpile swiper and its dependencies and all is working fine. // quasar.conf.js
module.exports = configure((ctx) => ({
build: {
transpileDependencies: ['swiper', 'swiper/vue', 'ssr-window', 'dom7'],
}
}); If you have any errors related to babel during webpack compilation, try to remove your Could be useful to you @yeus too. Try to add |
@freddy38510. Thank you! that last one worked with the amplify library. still have some small issues on how it is displayed. Such as it assumes the initial state is "logged in" for some reason... but working on those as well now ;). |
@yeus Good to know that you can now use the Vue components from Amplify lib. If the content of your pages is conditionnaly rendered by the Auth state, I would encourage you to not pre-render it. Otherwise, at first-load users will see the page rendered with the state initiated at build-time, then when Vue takes over, the content will change if the user is logged-in. This can only be handle at client-side. Do not pre-render these pages. Or use the Quasar I'm closing this issue since it is solved. |
================== GENERATE ==================
App • Cleaned build artifact: "C:\apps\vue\h5-off-site\dist\ssg"
Extension(ssg) • Copying assets...
Extension(ssg) • WAIT • Generating pages in progress...
[Vue Router warn]: uncaught error during route navigation:
[ Error: C:\apps\vue\h5-off-site\node_modules\swiper\vue\swiper-vue.js
require() of ES modules is not supported.
require() of C:\apps\vue\h5-off-site\node_modules\swiper\vue\swiper-vue.js from C: \apps\vue\h5-off-site\node_modules.cache\quasar-app-extension-ssg is an ES module file as it is a .js file whose nearest parent package.json contains "type": "modu le" which defines all .js files in that package scope as ES modules.
Instead rename swiper-vue.js to end in .cjs, change the requiring code to use impo rt(), or remove "type": "module" from C:\apps\vue\h5-off-site\node_modules\swiper\ package.json.
errors.js:322 new NodeError
internal/errors.js:322:7
loader.js:1102 Object.Module._extensions..js
internal/modules/cjs/loader.js:1102:13
loader.js:950 Module.load
internal/modules/cjs/loader.js:950:32
loader.js:790 Function.Module._load
internal/modules/cjs/loader.js:790:12
loader.js:974 Module.require
internal/modules/cjs/loader.js:974:19
helpers.js:93 require
internal/modules/cjs/helpers.js:93:18
create-bundle.js:56 _require
[h5-off-site]/[@quasar]/ssr-helpers/lib/create-bundle.js:56:9
render-app.js:491 Object.5804
render-app.js:491:18
render-app.js:555 webpack_require
render-app.js:555:41
chunk-392.js:386 Object.8072
chunk-392.js:386:68
] {
code: 'ERR_REQUIRE_ESM'
}
Extension(ssg) • DONE • Pages generated with errors • 101ms
Extension(ssg) • ERROR • Generate route /
Error: C:\apps\vue\h5-off-site\node_modules\swiper\vue\swiper-vue.js
require() of ES modules is not supported.
require() of C:\apps\vue\h5-off-site\node_modules\swiper\vue\swiper-vue.js from C: \apps\vue\h5-off-site\node_modules.cache\quasar-app-extension-ssg is an ES module file as it is a .js file whose nearest parent package.json contains "type": "modu le" which defines all .js files in that package scope as ES modules.
Instead rename swiper-vue.js to end in .cjs, change the requiring code to use impo rt(), or remove "type": "module" from C:\apps\vue\h5-off-site\node_modules\swiper\ package.json.
The text was updated successfully, but these errors were encountered: