Skip to content
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

SyntaxError: Cannot use import statement outside a module #4945

Closed
1 of 5 tasks
boboldehampsink opened this issue Nov 19, 2024 · 5 comments
Closed
1 of 5 tasks

SyntaxError: Cannot use import statement outside a module #4945

boboldehampsink opened this issue Nov 19, 2024 · 5 comments
Labels
🤔 needs reproduction This issue requires a demo

Comments

@boboldehampsink
Copy link

What happened?

Since 4.14.4 (specifically 4f88d85) I see this error when running my tests:

    /Users/boboldehampsink/Work/Robuust/zsm-brigante/node_modules/vee-validate/dist/vee-validate.mjs:6
    import { getCurrentInstance, inject, warn as warn$1, computed, toValue, ref, watch, nextTick, unref, isRef, reactive, onUnmounted, onMounted, provide, onBeforeUnmount, defineComponent, toRef, resolveDynamicComponent, h, readonly, watchEffect, shallowRef } from 'vue';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      27 | } from '@ionic/vue';
      28 |
    > 29 | import { defineRule } from 'vee-validate';
         | ^
      30 | import { required, min_value, numeric, email } from '@vee-validate/rules';
      31 |
      32 | config.global.mocks.$t = (key, params = null) => key;

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
      at Object.<anonymous> (tests/unit/index.js:29:1)

Reproduction steps

  1. Use 4.14.4 or higher
  2. Use Jest and add an index.js file, with in there: import { defineRule } from 'vee-validate';
  3. Run jest

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No response

Demo link

no

Code of Conduct

@logaretm logaretm added the 🤔 needs reproduction This issue requires a demo label Nov 19, 2024
@logaretm
Copy link
Owner

The bundles are now generated with .mjs extension and the main package type was changed to module which is neccessary for Vite/Nuxt moving forward. So I assume jest is having trouble figuring out which installation to use.

Try adding vee-validate to the transformIgnore patterns and see if that helps. If it doesn't please add a repo where this can be reproduced and I will take a look.

@logaretm logaretm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
@boboldehampsink
Copy link
Author

I tried adding vee-validate to transformIgnore, and also converted the whole project to type: module. Both to no avail. I do assume it's Jest tho, because it only fails in tests, not when running the app.

@boboldehampsink
Copy link
Author

Here is the same issue: jestjs/jest#9756 - and they're pointing to jestjs/jest#9430, which is still open

@logaretm
Copy link
Owner

I'm surprise they still hadn't closed that. I will check to see if there are any workarounds for that.

Wild suggestion: switch to Vitest 😅

@boboldehampsink
Copy link
Author

Yeah I have 3 options now: ignore the vee-validate update forever- or untill jest supports esm propertly. Or switch to vitest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 needs reproduction This issue requires a demo
Projects
None yet
Development

No branches or pull requests

2 participants