Closed tamysiby closed 1 year ago
When running quasar build -m ssr
or quasar ssg generate
command, it compiles both client-side and server-side outputs. The server-side compiled code is in CommonJs format.
The query-string
package is a pure ESM since its version 8.0.0.
So you need to transpile this library to commonJs. To do this, try adding this to your quasar.config.js file:
// quasar.config file
build: {
extendViteConf (viteConf, { isServer }) {
if(isServer) {
// see https://v2.vitejs.dev/config/#ssr-noexternal
viteConf.ssr = viteConf.ssr || { };
viteConf.ssr.noExternal = viteConf.ssr.noExternal || [];
viteConf.ssr.noExternal.push('query-string');
// if it doesn't work, try this instead:
// viteConf.ssr.noExternal.push(/query-string/);
}
}
}
Related to #309
Thank you for the explanation, and that solution worked for me! Thank you~
I get the following error
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/tamy/DD_ECO/qfrontend/node_modules/query-string/index.js from /home/tamy/DD_ECO/qfrontend/node_modules/.cache/quasar-app-extension-ssg/server/server-entry.js not supported. Instead change the require of index.js in /home/tamy/DD_ECO/qfrontend/node_modules/.cache/quasar-app-extension-ssg/server/server-entry.js to a dynamic import() which is available in all CommonJS modules. at Module.<anonymous> (/home/tamy/DD_ECO/qfrontend/node_modules/.cache/quasar-app-extension-ssg/server/server-entry.js:16:19) at createRenderFn (/home/tamy/DD_ECO/qfrontend/node_modules/quasar-app-extension-ssg/src/vite/ssg-create-render-fn.js:30:7) at SsgBuilder.generatePages (/home/tamy/DD_ECO/qfrontend/node_modules/quasar-app-extension-ssg/src/vite/ssg-builder.js:88:64) at run (/home/tamy/DD_ECO/qfrontend/node_modules/quasar-app-extension-ssg/src/vite/cmd/generate.js:126:20) { code: 'ERR_REQUIRE_ESM' }
and I'm not sure how to fix it since it seems like it's inside the quasar-app-extension's generated file? Is it a problem with the query-string library? How do I fix this?