ReferenceError: Vue is not defined

See original GitHub issue

Hi! Today I’m using karma + ( mocha, chai ) unit test in Vue 3, but I’ve got a reference issue: ReferenceError: Vue is not defined

I think it’s not a configuration problem and Vue global object should be removed in Vue 3, so maybe is VTU itself:

  ReferenceError: Vue is not defined
      at Object.<anonymous> (webpack:///node_modules/@vue/test-utils/dist/vue-test-utils.browser.js:2407:5 <- specs/Hello.spec.js:13561:7)
      at Object.<anonymous> (specs/Hello.spec.js:13563:30)
      at __webpack_require__ (webpack:///webpack/bootstrap:19:1 <- specs/Hello.spec.js:20:30)
      at Module.<anonymous> (webpack:///test/unit/specs/Hello.spec.js:1:1 <- specs/Hello.spec.js:95:73)
      at __webpack_require__ (webpack:///webpack/bootstrap:19:1 <- specs/Hello.spec.js:20:30)
      at webpack:///webpack/bootstrap:83:1 <- specs/Hello.spec.js:84:18
      at specs/Hello.spec.js:87:10

for more details you can check out and clone my repo (you may ignore the .yarnrc by the way): https://github.com/Styx11/vue3-boilerplate/tree/v0.0.1

Thanks : )

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
madpilot78commented, May 21, 2022

Hi,

I was migrating a Vue3 project from jest 27 to jest 28 and was seeing this error. I stumbled in this bug report, which moved me in the right direction. I decided to post my solution here in case someone else ends up here.

It turns out to be a non obvious configuration issue.

Obviously in this vue project I’m using the jest-environment-jsdom, which by default sets:

customExportConditions = ['browser'];

This is what causes the test suite to try to load the iife build, but the tests are really running in node, so the “fix” was to put this in my jest configuration (via package.json):

    "testEnvironment": "jsdom",
    "testEnvironmentOptions": {
      "customExportConditions": [
        "node",
        "node-addons"
      ]
    },

Changing the customExportConditions makes it load the correct file and everything now works.

Hope this information can be useful to others!

3reactions
madpilot78commented, May 24, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue is not defined - javascript - Stack Overflow
First, when you import the vue.js script you use type="JavaScript" as content-type which is wrong. You should remove this type parameter ...
Read more >
ReferenceError: Vue is not defined while using shallowMount ...
I am working on vue project and while doing unit testing using jest, I am getting following error for shallowMount: ReferenceError: Vue is...
Read more >
Uncaught ReferenceError: Vue is not defined - Laracasts
i watched the tutorial lets "flash messaging with vue - lets build a forum", i installed npm but at the end ... Uncaught...
Read more >
Fixing Uncaught ReferenceError: Vue is not defined with ...
While transitioning, I stumbled across this error: Uncaught ReferenceError: Vue is not defined. at eval (external “Vue”?548a:1). at Object.
Read more >
ReferenceError is not defined errors in production but works in ...
I made my first vue3 app, it is working in development but not in production (vite build). I've managed to re…
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found