quasarframework / quasar

Quasar Framework - Build high-performance VueJS user interfaces in record time
https://quasar.dev
MIT License
25.71k stars 3.49k forks source link

CLI Vite - using ViteConfig breaks building the app #12819

Closed smolinari closed 2 years ago

smolinari commented 2 years ago

What happened?

I have a Rush monorepo and using quasar dev I was getting 403s returned for some resource URLs. After investigating, I found the solution in adding a path to server.fs.allow of the Vite config object.

quasar.config.js

extendViteConf (viteConf) {
  viteConf.server.fs.allow = ['../../..']
}

This fixes the 403s, however, when I go to build the SPA, I get the following error:

...../packages/starter-kit-app/quasar.config.js:79
        viteConf.server.fs.allow = ['../../..']
                        ^

TypeError: Cannot read properties of undefined (reading 'fs')

What did you expect to happen?

No error during the build process.

Reproduction URL

I don't have one made.

How to reproduce?

  1. Add the value noted above to viteConf.
  2. Run quasar build

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app-webpack | @quasar/app-vite)

Platforms/Browsers

Chrome

Quasar info output

Operating System - Linux(5.13.0-35-generic) - linux/x64
NodeJs - 16.14.0

Global packages
  NPM - 8.5.2
  yarn - 1.22.17
  @quasar/cli - 1.3.0
  @quasar/icongenie - Not installed
  cordova - Not installed

Important local packages
  quasar - 2.6.0 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app-vite - 1.0.0-beta.3 -- Quasar Framework App CLI with Vite
  @quasar/extras - 1.12.5 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 3.2.31 -- The progressive JavaScript framework for building modern web UI.
  vue-router - 4.0.14
  pinia - Not installed
  vuex - Not installed
  vite - 2.8.6 -- Native-ESM powered web dev build tool
  eslint - 8.10.0 -- An AST-based pattern checker for JavaScript.
  electron - Not installed
  electron-packager - Not installed
  electron-builder - Not installed
  register-service-worker - Not installed
  @capacitor/core - Not installed
  @capacitor/cli - Not installed
  @capacitor/android - Not installed
  @capacitor/ios - Not installed

Quasar App Extensions
  *None installed*

Networking
  Host - scotts-ubuntu
  wlxbcec23c3706e - 192.168.178.67

Relevant log output

No response

Additional context

No response

github-actions[bot] commented 2 years ago

Hi @smolinari! 👋

It looks like you provided an invalid or unsupported reproduction URL. Do not use any service other than Codepen, jsFiddle, Codesandbox, and GitHub. Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc. Please edit your original post above and provide a valid reproduction URL as explained.

Without a proper reproduction, your issue will have to get closed.

Thank you for your collaboration. 👏

rstoenescu commented 2 years ago

Props in viteConf are not ensured. Different stuff happens based on what you are doing: dev or prod, what Quasar mode etc.

I can't stub all these because the presence of some objects changes the behavior of Vite in unwanted ways.

viteConf.server = viteConf.server || {}
viteConf.server.fs = viteConf.server.fs || {}
viteConf.server.fs.allow = ....
smolinari commented 2 years ago

Ok. So, I've put that line of code in an if statement based on the env.

extendViteConf (viteConf) {
  if (ctx.dev) {
    viteConf.server.fs.allow = ['../../..']
  }
}

And building is now working.

Scott