Skip to content

@lwc/rollup-plugin doesn't work with Vite #4628

Open
@danjunger

Description

@danjunger

Description

The LWC Rollup plugin seems to have a fundamental incompatibility with Vite's core set of plugins (which are not configurable). The issue stems from the fact that both the LWC Rollup plugin and Vite's build-html plugin attempt to transform LWC html files into javascript assets. It doesn't matter which plugin comes first in the chain, as either will break the other because both expect to receive valid html to transform (instead of the javascript that each plugin produces).

If Vite's build-html plugin comes first, it will also complain about LWC's html files lacking a doctype tag (ie <!DOCTYPE html>) as they typically only have a <template> tag along with their html snippets.

Steps to Reproduce

Example Vite configuration:

export default defineConfig({
    plugins: [
       lwc()
    ]
});

Expected Results

It would be nice if this "just worked" ™️.

Actual Results

Errors such as:

RollupError: src/modules/x/app/app.ts (1:9): "default" is not exported by "src/modules/x/app/app.html", imported by "src/modules/x/app/app.ts".

[CompilerError: [rollup-plugin-lwc-compiler] LWC1072: Missing root template tag file: /Users/djunger/code/electron-forge-vite/src/modules/x/app/app.html]

Browsers Affected

N/A

Version

All versions

Possible Solution

This may require a unique plugin distinct from the existing Rollup plugin, though it could also point to systemic integration issues with the LWC platform and its pseudo html templates.

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Vite/VitestCompatibility with Vite/Vitest/etcbug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions