Skip to content

Building to Vue 2 and 3: Version mismatch error from vue-template-compiler #11828

@privatenumber

Description

@privatenumber

What problem does this feature solve?

vue-template-compiler runs a version check against the vue specifier Node.js resolves as soon as it's imported here.

Because of this:

  1. I'm getting a vue-loader recommendation in a rollup build
  2. I can't have a setup that builds to both Vue 2 and 3. I think it's important to support this use-case for the eco-system as more apps migrate to Vue 3.

I'm interested in building a component to both Vue 2 and 3, but the version mismatch error from above gets thrown as soon as rollup-plugin-vue@5 is imported.

Screen Shot 2020-12-16 at 3 06 55 PM

My package.json looks like this:

{
  ...,
  "devDependencies": {
    "@vue/compiler-sfc": "^3.0.4",
    "rollup": "^2.35.1",
    "rollup-plugin-vue2": "npm:rollup-plugin-vue@^5.1.9",
    "rollup-plugin-vue3": "npm:rollup-plugin-vue@^6.0.0",
    "vue": "^3.0.4",
    "vue-template-compiler": "^2.6.12",
    "vue2": "npm:vue@^2.6.12"
  }
}

My rollup.config.js looks like this:

import vue2 from 'rollup-plugin-vue2';
import vue3 from 'rollup-plugin-vue3';

const rollupConfig = [
    {
        input: 'src/MyComponent.vue',
        plugins: [
            vue3(),
        ],
        output: {
            format: 'es',
            file: 'dist/my-component.vue3.esm.js',
        },
    },
    {
        input: 'src/MyComponent.vue',
        plugins: [
            vue2(),
        ],
        output: {
            format: 'es',
            file: 'dist/my-component.vue2.esm.js',
        },
    },
];

export default rollupConfig;

What does the proposed API look like?

Wondering if this can be changed to a run-time check or moved to the appropriate loader/plugin.

A run-time check might be a good idea as I'm sure a lot of people may be accidentally trying to import Vue 2 components into a Vue 3 app and vice-versa.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions