quasar
quasar copied to clipboard
How to re-enable "global" in SSR mode?
What happened?
Basic libraries like "graceful-fs" or "file-system-cache" are requiring global. It is not available in the SSR-Mode.
So we can not use these libs server side and instead get errors like:
ReferenceError: global is not defined
What did you expect to happen?
global variable still exists.
Reproduction URL
https://stackblitz.com/edit/quasarframework-eygtuk?file=quasar.config.js
How to reproduce?
Either start the demo project from here in SSR mode: https://stackblitz.com/edit/quasarframework-eygtuk?file=quasar.config.js
or setup easily from scratch:
-
setup a new quasar applciation
yarn add file-system-cache
- server side, like in a boot file enabled for server and disabled for client:
const cache = Cache({})
Flavour
Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)
Areas
TypeScript Support, SSR Mode
Platforms/Browsers
No response
Quasar info output
Operating System - Darwin(22.6.0) - darwin/arm64
NodeJs - 18.17.1
Global packages
NPM - 9.6.7
yarn - 1.22.19
@quasar/cli - 2.3.0
@quasar/icongenie - Not installed
cordova - Not installed
Important local packages
quasar - 2.12.3 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
@quasar/app-vite - 1.4.3 -- Quasar Framework App CLI with Vite
@quasar/extras - 1.16.5 -- Quasar Framework fonts, icons and animations
eslint-plugin-quasar - Not installed
vue - 3.3.4 -- The progressive JavaScript framework for building modern web UI.
vue-router - 4.2.4
pinia - 2.1.4 -- Intuitive, type safe and flexible Store for Vue
vuex - Not installed
vite - 2.9.16 -- Native-ESM powered web dev build tool
eslint - 8.45.0 -- An AST-based pattern checker for JavaScript.
electron - Not installed
electron-packager - Not installed
electron-builder - Not installed
register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
@capacitor/core - Not installed
@capacitor/cli - Not installed
@capacitor/android - Not installed
@capacitor/ios - Not installed
Quasar App Extensions
*None installed*
Relevant log output
Uncaught (in promise) ReferenceError: global is not defined
at node_modules/graceful-fs/graceful-fs.js (graceful-fs.js:45:7)
at __require (chunk-J43GMYXM.js?v=157be694:11:50)
at node_modules/fs-extra/lib/fs/index.js (index.js:5:12)
at __require (chunk-J43GMYXM.js?v=157be694:11:50)
at node_modules/fs-extra/lib/index.js (index.js:5:6)
at __require (chunk-J43GMYXM.js?v=157be694:11:50)
at node_modules/file-system-cache/lib/common/libs.js (libs.js:32:36)
at __require (chunk-J43GMYXM.js?v=157be694:11:50)
at node_modules/file-system-cache/lib/common/util.js (util.js:13:16)
at __require (chunk-J43GMYXM.js?v=157be694:11:50)
Additional context
No response
As far as I know, there is no default globals variable as there is for window. So this shouldn't be related to SSR, but probably a dependency of either one of those packages uses globals which looks like a CJS only package.
I'd advise to find a ESM alternative to those packages,