Skip to content

Babel rewire not working after upgrade to Vue3 #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
colingm opened this issue Apr 4, 2025 · 0 comments
Open

Babel rewire not working after upgrade to Vue3 #569

colingm opened this issue Apr 4, 2025 · 0 comments

Comments

@colingm
Copy link

colingm commented Apr 4, 2025

We have recently migrated from Vue2 to Vue3 and in the process we were having problems with testing. Our setup is to use Jest and then also babel-plugin-rewire to be able to mock functions from the same module as the unit under test. The setup in Vue2 worked just fine but after upgrading to Vue3 (and really vue3-jest) the setup began to fail claiming RewireAPI had already been declared.

    /Users/colin.maxfield/workspace/test-sites/vue-jest-examples/sanity/src/components/TheWelcome.vue:430
    var _RewireAPI__ = exports.__RewireAPI__ = {};
        ^

    SyntaxError: Identifier '_RewireAPI__' has already been declared

After digging in to the process function of vue3-jest it seemed like all of the Vue special imports were being rewired but separately from the script of the component resulting in a lot of attempts to declare things by the same name (like the error above). I setup a simple sanity test for both Vue3 and Vue2 and found that the same setup passes in Vue2 but fails in Vue3 (https://github.com/colingm/vue-jest-examples).

In my test repo there is a .babelrc that is setup with babel-env like below and I found that if I removed the environment configuration there that the Vue3 version also started to work (sadly we need those in our project). Any ideas on where I could dig in code to try to find what the difference is or something that might help here?

"@babel/env",
            {
                "targets": [
                    "defaults"
                ],
                "useBuiltIns": "usage",
                "corejs": "3"
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant