fix(addon-bangumi): runtime error in browser #431
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Restored
valaxy-addon-bangumi
to a basic working state.At this line, the following error occurs:
valaxy/packages/valaxy-addon-bangumi/components/ValaxyBangumi.vue
Line 10 in a58ca38
In this case, a wildcard import should be used:
However, this change causes a
ReferenceError: exports is not defined
in the browser environment when running the code, which stems from the followingloader.cjs
file:In general, using CommonJS in browser environments is problematic and would require additional configuration in
tsconfig.json
. Therefore, it's better to stick to ESM when possible.Regarding issue #346, it’s important to clarify that in Vite 6, ESM modules should use the
.mjs
or.mts
extensions; otherwise, they might be treated as CJS. As mentioned in the Vite CJS Node API deprecated notice, using the.mjs
/.mts
extensions for ESM files is recommended. Although setting"type": "module"
inpackage.json
is an option, it may have unintended consequences for thebilibili-bangumi-component
CommonJS module.Given that this is a Vite-specific issue, and since the browser environment natively supports ESM, a dynamic import in the browser can be used as a workaround. Nonetheless, this is a hacky solution, and it’s preferable for
bilibili-bangumi-component
to receive broader support for ESM.