question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Frontend broke with VAADIN 23.2.0 due to Vite being used and not allowing `require` anymore

See original GitHub issue

Description of the bug

After updating from VAADIN 23.1.7 to VAADIN 23.2.0, the (main page of the) application can’t be displayed anymore. In the Chrome console, the error is simple:

Uncaught (in promise) ReferenceError: require is not defined at generated-flow-imports.9cd14ffe.js:formatted:58387:10

As far as I know, VAADIN 23.2.0 started to use Vite instead of Webpack where Vite simply doesn’t allow require to be used due to ES5 compatibility(?).

We had several usages of require in our frontend where I was able to eliminate most of them, except for 2 usages.

  • cytoscape-expand-collapse (has no module support yet)
  • cytoscape-node-html-label (has invalid module support)

I researched a lot for possible solutions finding - amongst others - the following issue: https://github.com/vitejs/vite/issues/3409 Sadly, none of the mentioned solutions (using the vite-plugin-commonjs plugin and using transformMixedEsModules: true) worked out for me.

I also tried setting "module": "commonjs" in my tsconfig.json but that didn’t work out either due to exporting my own classes / components.

I know this is not really a bug but how are we supposed to migrate our projects in such a case? In my case the TS file throwing the error is nearly 3 years old and the last change was over a year ago.

Minimal reproducible example

See this example project: project-with-require.zip (with Git history)

On commit cb4143d9cbc484cb2c2aaed59977737f174409a8, the project works as expected when using VAADIN 23.1.7. After updating to VAADIN 23.2.0 (ec6e6b64e46b622eb8641634ec5fe40455524558, state of the ZIP), the same error message from above will be displayed in the Browser console.

Expected behavior

I expect the application to show the main page.

Actual behavior

Even the main page is not showing up anymore, the site looks like it’s loading forever. An error can be found in the Browser console.

image

Versions:

- Vaadin / Flow version: VAADIN 23.2.0
- Java version: 17.0.2 2022-01-18 LTS
- OS version: Windows 10 21H1
- Browser version (if applicable): Not needed.
- Application Server (if applicable): Not needed.
- IDE (if applicable): Not needed.
- Development or production mode: Both.
- Project from start.vaadin.com or activated in application: See minimal reproducible example above.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Artur-commented, Sep 8, 2022

If you use import f from 'fetch-retry'; instead it seems TypeScript gets the type correctly

1reaction
knoobiecommented, Sep 5, 2022

For the meantime you could still use webpack which is behind a “feature / deprecation” flag to allow the flow team to find a proper solution and still be on the latest version

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vaadin 23.2: Better than ever
The support is now official, and Vite is replacing Webpack to speed up the automated frontend bundling for faster front-end build times. You ......
Read more >
Vaadin: How do I get rid of vite? - Stack Overflow
Disabling Vite in the lower right control-dialog is not accepted, it remains activated. How do I get rid of this unbaked feature again?...
Read more >
Still 100% Java for frontend development – A.Mahdy AbdelAziz
Vaadin announced about its next major framework: Vaadin Flow. The biggest change in this version is a focus on PWA and the usage...
Read more >
vaadin/flow 23.2.0 on GitHub - NewReleases.io
It no longer relies on third party cookies to resolve all browser compatibility issues. Use Vite as a primary tool. Commit · Pull...
Read more >
Why is Vaadin's adoption small? : r/java - Reddit
Since with Vaadin is easy much easier to build the frontend than with the JS ... No need to use a client state-driven...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found