-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Which component is affected?
Qwik Optimizer (rust)
Describe the bug
Related to #5097, but creating another issue because the two will probably be solved independently.
In an attempt to solve the big bundle and tree-shaking issue in qwik-ui, which is also an issue for any other qwik library using the library starter, @shairez and @wmertens found that setting build.rollupOptions.output.preserveModules to true can work around the issue. But the problem is that this introduces a namespace issue in preview and production with "error code 31" and the error message "Cannot resolve symbol s_c7PiYJ1s0GU".
So using
rollupOptions: {
output: {
preserveModules: true,
preserveModulesRoot: 'packages/kit-headless/src',
},
},if the library has a component$ named AccordionRoot, and then I define export const AccordionRoot = component$(...) in the local app, the AccordionRoot component from the library will be overridden by the AccordionRoot in the local app, leading to "Cannot resolve symbol s_c7PiYJ1s0GU... Error code (31)" types of errors when symbols cannot reach the qwik-ui's AccordionRoot code as it isn't there.
We believe the code isn't there because it is the local project's AccordionRoot that is in the build output instead.
Reproduction
https://github.com/maiieul/qwik-libraryMode-and-preserveModules-namespace-issue-repro
Steps to reproduce
To see the error message:
- Clone the repo
npm i(npm will make the debugging step easier)npm run preview
Go into src/components/accordion-root/index.tsx and change the const to AccordionRoot2 and the error will go away.
System Info
System:
OS: Linux 6.5 Fedora Linux 38 (Workstation Edition)
CPU: (16) x64 13th Gen Intel(R) Core(TM) i5-1340P
Memory: 17.00 GB / 31.04 GB
Container: Yes
Shell: 3.6.1 - /usr/bin/fish
Binaries:
Node: 20.9.0 - /usr/local/bin/node
npm: 10.1.0 - /usr/local/bin/npm
pnpm: 8.10.5 - ~/.local/share/pnpm/pnpm
Browsers:
Chrome: 119.0.6045.159
npmPackages:
@builder.io/partytown: ^0.8.1 => 0.8.1
@builder.io/qwik: ^1.2.18 => 1.2.18
@builder.io/qwik-city: ^1.2.18 => 1.2.18
@builder.io/qwik-react: 0.5.0 => 0.5.0
undici: 5.27.0 => 5.27.0
vite: 4.5.0 => 4.5.0Additional Information
@shairez and I have been through a lot of steps to identify the bug, but we believe it's an optimizer issue and couldn't get further. It will probably be easier to go through this in a live session, but I wrote the steps here in case someone has to go over them later on.
To understand the error:
- Go into VScode debugger
- Open node_modules/@builder.io/qwik/optimizer.cjs
- Watch for
newOutput,currentOuputs, anddeps - Put a breakpoint on line 2087 (here, the transform function is setting the newOutput modules into the currentOutputs Map)
- Start the build.client debugger
- In your WATCH panel, observe that at
currentOutputs[31], there is a key withentry_AccordionRoot.js - In your WATCH panel, observe that at
newOutput.modules[10], the path is "/qwik-ui-tabs-repro/src/entry_AccordionRoot.js", but atcurrentOutputs[31], there is already a key withentry_AccordionRoot.jsthat has already been set at line 2020. - Press the "Continue (F5)" button 10 times and see the
entry_AccordionRoot.jsof the local project being overridden by the one from qwik-ui. I was expecting the opposite, so I guess that by the time this override happens, the local project entry file has already been outputted into the build folder and so Rollup, Vite, or the Plugin can't output it again.
Either way, we believe the crux of the issue lies in the fact that the path is the same for both AccordionRoot components ("entry_AccordionRoot.js"). A global search makes it look like this is being set in packages/qwik/src/optimizer/core/src/entry_strategy.rs.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status