Skip to content
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

Vite plugin: setTimeout() in stylesPlugin.ts #225

Closed
BreizhReloaded opened this issue Dec 7, 2021 · 22 comments
Closed

Vite plugin: setTimeout() in stylesPlugin.ts #225

BreizhReloaded opened this issue Dec 7, 2021 · 22 comments
Labels

Comments

@BreizhReloaded
Copy link

BreizhReloaded commented Dec 7, 2021

Hello,

I get This variable was not declared with !default in the @used module when overriding component Sass variables. It's not always the same variable, and the build goes sometimes through. It's less common a on small project than on a bigger one. When it crashes, the .scss cache file it not complete.

I couldn't find a defined protocol to reproduce the error all the time (working on it), but I can say at the moment that it's not OS-related (tested on Windows, WSL and Ubuntu).

That seems to happen randomly, which is quite annoying. After some analysis, it seems to be related with the setTimeout() call in stylesPlugin.ts. Setting a bigger time value reduces my build error rate. What is this call made for? Why 500ms exactly?

Thanks!

Edit: obviously working with the alpha 9, and using the latest Vuetify nightly.

@KaelWD
Copy link
Member

KaelWD commented Dec 8, 2021

What is this call made for?

We need to wait for all the other modules to resolve so we can collect all the used components. 500ms was just a guess that seemed to work most of the time, I need to see if there's an actual way to wait until no other modules are pending.

@KaelWD KaelWD added the bug label Dec 8, 2021
@KaelWD
Copy link
Member

KaelWD commented Dec 8, 2021

Can you try with this? vuetify-vite-plugin-1.0.0-alpha.9.tar.gz (npm install /path/to/tar.gz)

Add DEBUG='vuetify:*' before your dev command to see debug info.

@KaelWD
Copy link
Member

KaelWD commented Dec 8, 2021

Rollup doesn't expose pendingRequests unfortunately, it needs something like this to work for production builds too:

diff --git a/node_modules/rollup/dist/shared/rollup.js b/node_modules/rollup/dist/shared/rollup.js
index 3ea3308..494e346 100644
--- a/node_modules/rollup/dist/shared/rollup.js
+++ b/node_modules/rollup/dist/shared/rollup.js
@@ -21969,6 +21969,8 @@ function transform(source, module, pluginDriver, warn) {
     });
 }
 
+const pendingRequests = new Map()
+
 class ModuleLoader {
     constructor(graph, modulesById, options, pluginDriver) {
         this.graph = graph;
@@ -22155,7 +22157,13 @@ class ModuleLoader {
         const module = new Module(this.graph, id, this.options, isEntry, moduleSideEffects, syntheticNamedExports, meta);
         this.modulesById.set(id, module);
         this.graph.watchFiles[id] = true;
-        await this.addModuleSource(id, importer, module);
+        const promise = this.addModuleSource(id, importer, module)
+        pendingRequests.set(id, promise)
+        await promise;
+        pendingRequests.delete(id)
         const resolveStaticDependencyPromises = this.getResolveStaticDependencyPromises(module);
         const resolveDynamicImportPromises = this.getResolveDynamicImportPromises(module);
         Promise.all([
@@ -22401,6 +22409,7 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
         cacheInstance = getCacheForUncacheablePlugin(plugin.name);
     }
     const context = {
+        pendingRequests,
         addWatchFile(id) {
             if (graph.phase >= BuildPhase.GENERATE) {
                 return this.error(errInvalidRollupPhaseForAddWatchFile());

@BreizhReloaded
Copy link
Author

Ok, that explains everything, thank you very much for your quick answer. I'm trying your build this afternoon, I'm coming back to you right after. I thought about a possible workaround: would it be possible to set the time based on the number of files/imports? Do you intend to suggest that update to rollup?

@KaelWD
Copy link
Member

KaelWD commented Dec 8, 2021

rollup/rollup#4294

would it be possible to set the time based on the number of files/imports?

Not really, it depends on the size of the project (and processor speed/other plugins) which we don't know until the build is complete.

@KaelWD
Copy link
Member

KaelWD commented Dec 9, 2021

@BreizhReloaded Did you try with my changes?

@BreizhReloaded
Copy link
Author

BreizhReloaded commented Dec 9, 2021

Hello,

Sorry I took time to answer. I tried your fix and got:

transforming (48) node_modules/yup/es/index.js  vuetify:styles awaiting /mnt/c/Users/franc/Projects/opale/front-office/src/main.scss +0ms
/mnt/c/Users/franc/Projects/opale/front-office/node_modules/@vuetify/vite-plugin/dist/stylesPlugin.js:25
        return Object.entries(server._pendingRequests)
                                     ^

TypeError: Cannot read properties of undefined (reading '_pendingRequests')
    at getPendingModules (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/@vuetify/vite-plugin/dist/stylesPlugin.js:25:38)
    at Timeout._onTimeout (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/@vuetify/vite-plugin/dist/stylesPlugin.js:39:36)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

The currently transforming file is always different when it crashes.

@BreizhReloaded
Copy link
Author

That's from WSL, but I got the same result from Windows.

@KaelWD
Copy link
Member

KaelWD commented Dec 10, 2021

Yeah it won't work in build mode, only development

@BreizhReloaded
Copy link
Author

Stupid me.

Here it it:

  vuetify:styles awaiting C:/Users/franc/Projects/opale/front-office/src/main.scss +0ms
  vuetify:styles poll +119ms
  vuetify:styles poll +262ms
  vuetify:styles poll +703ms
  vuetify:styles poll +461ms
vuetify:styles fallback timeout hit {
  blockingModules: [ 'C:/Users/franc/Projects/opale/front-office/src/main.scss' ],
  pendingModules: []
}
  vuetify:styles writing styles +7ms
  vuetify:styles poll +99ms
  vuetify:styles poll +150ms
  vuetify:styles poll +297ms
  vuetify:styles poll +103ms
  vuetify:styles poll +102ms
  vuetify:styles poll +129ms
  vuetify:styles poll +240ms
  vuetify:styles poll +103ms
  vuetify:styles poll +179ms
  vuetify:styles poll +682ms
  vuetify:styles poll +242ms
  vuetify:styles poll +9s
  vuetify:styles poll +1s
  vuetify:styles poll +106ms
  vuetify:styles poll +103ms
  vuetify:styles poll +103ms
  vuetify:styles poll +111ms
  vuetify:styles poll +111ms
  vuetify:styles poll +111ms
  vuetify:styles poll +111ms
  vuetify:styles poll +110ms
  vuetify:styles poll +107ms
  vuetify:styles poll +107ms
  vuetify:styles poll +103ms
  vuetify:styles poll +107ms
  vuetify:styles poll +103ms

After that, it's only calls between 100ms and 120ms.

@BreizhReloaded
Copy link
Author

Interestingly, the result is a bit different from WSL:

vuetify:styles awaiting /mnt/c/Users/franc/Projects/opale/front-office/src/main.scss +0ms
  vuetify:styles poll +436ms
vuetify:styles fallback timeout hit {
  blockingModules: [ '/mnt/c/Users/franc/Projects/opale/front-office/src/main.scss' ],
  pendingModules: []
}
  vuetify:styles writing styles +3s
  vuetify:styles poll +1ms
  vuetify:styles poll +3s
  vuetify:styles poll +128ms
vuetify:styles fallback timeout hit {
  blockingModules: [ '/mnt/c/Users/franc/Projects/opale/front-office/src/main.scss' ],
  pendingModules: []
}
  vuetify:styles poll +855ms
  vuetify:styles poll +164ms
  vuetify:styles poll +292ms
  vuetify:styles poll +1s
  vuetify:styles poll +3s
  vuetify:styles poll +237ms
  vuetify:styles poll +225ms
  vuetify:styles poll +118ms
  vuetify:styles poll +358ms
  vuetify:styles poll +235ms
  vuetify:styles poll +299ms
  vuetify:styles poll +228ms
  vuetify:styles poll +623ms
  vuetify:styles poll +1s
  vuetify:styles poll +190ms
  vuetify:styles poll +153ms
  vuetify:styles poll +982ms
  vuetify:styles poll +160ms
  vuetify:styles poll +120ms
  vuetify:styles poll +179ms
  vuetify:styles poll +194ms
  vuetify:styles poll +2s
  vuetify:styles poll +126ms
  vuetify:styles poll +105ms
  vuetify:styles poll +678ms
  vuetify:styles poll +231ms
  vuetify:styles poll +133ms
  vuetify:styles poll +237ms
  vuetify:styles poll +208ms
  vuetify:styles poll +918ms
  vuetify:styles poll +408ms
9:50:47 AM [vite] Internal server error: This variable was not declared with !default in the @used module.
  ╷
7 │   $button-height: opale.$button-height,
  │   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  src/main.scss 7:3  root stylesheet
  Plugin: vite:css
  File: /mnt/c/Users/franc/Projects/opale/front-office/src/main.scss
  Error: This variable was not declared with !default in the @used module.
    ╷
  7 │   $button-height: opale.$button-height,
    │   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵
    src/main.scss 7:3  root stylesheet
      at Object.wrapException (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:6290:17)
      at _EvaluateVisitor2._async_evaluate0$_assertConfigurationIsEmpty$2$nameInError (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:67605:15)
      at _EvaluateVisitor2._async_evaluate0$_assertConfigurationIsEmpty$1 (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:67608:19)
      at /mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:68741:27
      at _wrapJsFunctionForAsync_closure.$protected (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:12048:15)
      at _wrapJsFunctionForAsync_closure.call$2 (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:26877:12)
      at _awaitOnObject_closure.call$1 (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:26865:32)
      at Object._rootRunUnary (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:12422:18)
      at StaticClosure.<anonymous> (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:94428:16)
      at _CustomZone.runUnary$2$2 (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:28272:39)
  vuetify:styles poll +7s
  vuetify:styles poll +103ms
  vuetify:styles poll +123ms
  vuetify:styles poll +151ms
  vuetify:styles poll +101ms

@KaelWD
Copy link
Member

KaelWD commented Dec 10, 2021

Turns out that one only works in vite 2.6, I've pushed an improved version that should work with 2.7 (and prod mode)

Built: vuetify-vite-plugin-1.0.0-alpha.9.tar.gz

@BreizhReloaded
Copy link
Author

Ok. Here is the result with your new build, for Windows:

vite v2.7.1 dev server running at:

  > Local: http://localhost:8081/
  > Network: use `--host` to expose

  ready in 6077ms.

  vuetify:styles awaiting C:/Users/franc/Projects/opale/front-office/src/main.scss +0ms
  vuetify:styles writing styles +3s

And WSL:

vite v2.7.1 dev server running at:

  > Local: http://localhost:8081/
  > Network: use `--host` to expose

  ready in 21284ms.

  vuetify:styles awaiting /mnt/c/Users/franc/Projects/opale/front-office/src/main.scss +0ms
vuetify:styles fallback timeout hit {
  blockingModules: [ '/mnt/c/Users/franc/Projects/opale/front-office/src/main.scss' ],
  pendingModules: undefined
}
  vuetify:styles writing styles +11s

No more logs after that, even when I move across the webapp.

@KaelWD
Copy link
Member

KaelWD commented Dec 10, 2021

Hmm, not sure why it's hitting the timeout there. What happens if you reduce it back to 500ms?

@BreizhReloaded
Copy link
Author

BreizhReloaded commented Dec 10, 2021

With timer reduced from 10s to 500ms, on Windows:

vite v2.7.1 dev server running at:

  > Local: http://localhost:8081/
  > Network: use `--host` to expose

  ready in 4994ms.

  vuetify:styles awaiting C:/Users/franc/Projects/opale/front-office/src/main.scss +0ms
vuetify:styles fallback timeout hit {
  blockingModules: [ 'C:/Users/franc/Projects/opale/front-office/src/main.scss' ],
  pendingModules: undefined
}
  vuetify:styles writing styles +793ms

On WSL, I got the override error back. But that makes sense, because it's a NTFS folder, access is slower. I can make a test on a regular WSL folder, not a mounted one if you're interested.

  vite v2.7.1 dev server running at:

  > Local: http://localhost:8081/
  > Network: use `--host` to expose

  ready in 21534ms.

  vuetify:styles awaiting /mnt/c/Users/franc/Projects/opale/front-office/src/main.scss +0ms
vuetify:styles fallback timeout hit {
  blockingModules: [ '/mnt/c/Users/franc/Projects/opale/front-office/src/main.scss' ],
  pendingModules: undefined
}
  vuetify:styles writing styles +2s
11:38:02 AM [vite] Internal server error: This variable was not declared with !default in the @used module.
  ╷
7 │   $button-height: opale.$button-height,
  │   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  src/main.scss 7:3  root stylesheet
  Plugin: vite:css
  File: /mnt/c/Users/franc/Projects/opale/front-office/src/main.scss
  Error: This variable was not declared with !default in the @used module.
    ╷
  7 │   $button-height: opale.$button-height,
    │   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵
    src/main.scss 7:3  root stylesheet
      at Object.wrapException (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:6290:17)
      at _EvaluateVisitor2._async_evaluate0$_assertConfigurationIsEmpty$2$nameInError (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:67605:15)
      at _EvaluateVisitor2._async_evaluate0$_assertConfigurationIsEmpty$1 (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:67608:19)
      at /mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:68741:27
      at _wrapJsFunctionForAsync_closure.$protected (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:12048:15)
      at _wrapJsFunctionForAsync_closure.call$2 (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:26877:12)
      at _awaitOnObject_closure.call$1 (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:26865:32)
      at Object._rootRunUnary (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:12422:18)
      at StaticClosure.<anonymous> (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:94428:16)
      at _CustomZone.runUnary$2$2 (/mnt/c/Users/franc/Projects/opale/front-office/node_modules/sass/sass.dart.js:28272:39)

@KaelWD
Copy link
Member

KaelWD commented Dec 10, 2021

Can you change line 49 (the timeout log) from pendingModules to pendingModules: Array.from(server._pendingRequests.keys()) and try again?

File system isn't really relevant here, in fact the WSL example is probably helpful because it's so much slower than normal.

@BreizhReloaded
Copy link
Author

And with all the keys:

vite v2.7.1 dev server running at:

  > Local: http://localhost:8081/
  > Network: use `--host` to expose

  ready in 1901ms.

  vuetify:styles awaiting /mnt/c/Users/franc/Projects/opale/front-office/src/main.scss +0ms
vuetify:styles fallback timeout hit {
  blockingModules: [ '/mnt/c/Users/franc/Projects/opale/front-office/src/main.scss' ],
  pendingModules: [
    '/src/main.scss',
    '/src/components/AppFooter.vue',
    '/src/components/AppHeader.vue',
    '/src/components/AppMain.vue',
    '/src/components/ColImagePanels.vue',
    '/src/components/NavigationRow.vue',
    '/src/components/ProgressRow.vue',
    '/src/components/UserMenu.vue',
    '/src/components/DialogWrapper.vue?vue&type=style&index=0&lang.scss',
    '/src/locales/fr/index.ts',
    '/package.json',
    '/src/components/AppFooter.vue?vue&type=style&index=0&lang.scss',
    '/src/components/ColImagePanels.vue?vue&type=style&index=0&lang.scss',
    '/src/pages/private/Dashboard/Dashboard.vue',
    '/src/pages/private/Fund/Fund.vue',
    '/src/pages/private/Funds/Funds.vue',
    '/src/pages/private/KYC/KYC.vue',
    '/src/pages/private/Subscribe/Subscribe.vue',
    '/src/pages/public/AboutUs/AboutUs.vue',
    '/src/pages/public/Home/Home.vue',
    '/src/pages/public/Login/Login.vue',
    '/src/pages/public/Logout/Logout.vue',
    '/src/pages/public/Offer/Offer.vue',
    '/src/pages/public/Register/Register.vue'
  ]
}
  vuetify:styles writing styles +3s

@KaelWD
Copy link
Member

KaelWD commented Dec 10, 2021

Is that still with the short timeout?

@BreizhReloaded
Copy link
Author

Yes, 500ms. It doesn't trigger the error at 10s now, even on WSL.

@KaelWD
Copy link
Member

KaelWD commented Dec 10, 2021

Ok I guess that's fixed then. In alpha 10 I also added an option to configure the timeout just in case.

@KaelWD KaelWD closed this as completed Dec 10, 2021
@BreizhReloaded
Copy link
Author

Lovely, huge thanks for your help Kael. I'm giving a try at the alpha 10 and let you know if I notice anything. Have a nice weekend!

@BreizhReloaded
Copy link
Author

BreizhReloaded commented Dec 10, 2021

Alpha 10 works like a charm on Windows, but crashes on WSL. That said, let's be honest: it's not a really good habit to work via WSL on a NTFS folder. I haven't tried it yet, but I'm sure it's ok on a regular non-mounted WSL folder.

(I'm writing this in case people hit the same error when working on folders shared on different file systems, like containers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants