Open Artur- opened 2 years ago
Reduced test case https://github.com/Artur-/vite-vaadin-problem8
Shows a different error message Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "dom-module" has already been used with this registry
but seems to be caused by the same problem. The error is gone when removing the exclude
part of optimizeDeps
Any idea about this @patak-dev or what to even dig for?
I simplified the test even further to not use external npm packages.
The problem seems to happen when a project source file imports a file from a node_modules package directly (test/multiple.js
) and also imports it through an npm package that is exclude from optimization (@vaadin/flow-frontend/importer2.js
-> test/intermediate.js
-> ./multiple.js
)
the original file in the browser becomes
import '/@fs/.../node_modules/@vaadin/flow-frontend/importer2.js?v=5621ba1f';
import "/@fs/.../node_modules/.vite/deps/test_multiple__js.js?v=ca346643"
where @vaadin/flow-frontend/importer2.js
imports the files individually, first intermediate.js
and then multiple.js
but .vite/deps/test_multiple__js.js?v=ca346643
does not import multiple.js
but instead contains the code from multiple.js
@Artur- any update on this?
Describe the bug
In a very specific case when the same file is imported through (at least) two different import chains, the file is in the first case loaded from a chunk
node_modules/.vite/deps/chunk-RQANFN22.js?v=0a6e73b8
and then later on loaded from the source filenode_modules/@vaadin/vaadin-lumo-styles/version.js?v=0a6e73b
. As import has side effects, this crashes the whole application.The case has worked fine but breaks when when
@vaadin/flow-frontend
is added tooptimizeDeps.exclude
.The imports seem to go like this:
vaadin.ts
Chain 1
/VAADIN/generated/theme.js
/VAADIN/generated/theme-vite-basics.generated.js
node_modules/.vite/deps/@vaadin_vaadin-lumo-styles_color__js.js?v=0a6e73b8
node_modules/.vite/deps/chunk-RQANFN22.js?v=0a6e73b8
Chain 2
target/frontend/generated-flow-imports.js
node_modules/@vaadin/flow-frontend/lumo-includes.ts?v=0a6e73b8
node_modules/@vaadin/vaadin-lumo-styles/all-imports.js?v=0a6e73b8
node_modules/@vaadin/vaadin-lumo-styles/font-icons.js?v=0a6e73b8
node_modules/@vaadin/vaadin-lumo-styles/version.js?v=0a6e73b8
Reproduction
https://github.com/vaadin/flow
Steps to reproduce
git clone git@github.com:vaadin/flow.git cd flow git checkout a5d27d93df6ebebcd779872cf1076c87a8b174de mvn install -DskipTests cd flow-tests mvn jetty:run -DskipTests -am -pl test-frontend/vite-basics open http://localhost:8888
System Info
Used Package Manager
pnpm
Logs
https://gist.github.com/Artur-/1cfc2cc29fbe475376d35ab5dd4a6c2c
Validations