- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
"Unexpected token export" when importing validation rules with Jest #2310
Comments
If we change the Generally, you should solve this issue by adding an exception for vee-validate in your babel config which is what Nuxt does under the hood. |
Thanks for your reply @logaretm I'm not an expert on packaging, but you can offer other module formats without losing the tree-shaking capabilities. We offer Angular as an UMD and Anyway, to come back to the issue, my point was: in a TS project, you don't have a Babel config. So the example in the doc is not enough to solve it. I think the issue should be reopened until figured out and properly documented, or that the bundling format is fixed on your part. As more and more Vue project are going to use TS with Vue 3, it would be awesome to have vee-validate working out of the box of course :) I look forward to properly test vee-validate v3 once this is fixed! |
Agreed, I will tag this as an enhancement for now. |
I end up importing the full package and it works import {
localize,
setInteractionMode,
} from 'vee-validate/dist/vee-validate.full'
import fr from 'vee-validate/dist/locale/fr.json'
localize({
fr,
})
setInteractionMode('eager') |
I have added a |
@cexbrayat Have you tried adding a transform ignore pattern to your jest configuration file/object? transformIgnorePatterns: ['/node_modules/(?!vee-validate/dist/rules)'], |
@aholzner I did, but in a TS project, it's not enough. Maybe because there is no transformer for JS files. But even adding |
I just created a new project as you mentioned in your project, but I installed these dependencies as well:
And the tests ran without any problems, I didn't have to configure babel-jest to handle js files as I think the If this is still an issue for you, you could try to upload a broken repository. I will PR it with my changes and see if that works. |
@logaretm Thank you for taking the time to explore this issue. I tried your workaround but no luck for me.
and you should reproduce (or I missed something). The last commit contains your workaround. (Even if this was the proper workaround, it would still be sad to have to set up extra deps just to run tests for one library whereas the rest of the eco-system does not need this) |
If anyone stumbles on this issue, I managed to make it work by using Vue CLI v4 (currently in RC), because it uses Jest 24. Then you'll need to add a basic Babel config and |
@logaretm its still an issue. |
@aldarund It's just the There is a |
@logaretm I dont think tree shaking is working. I dont see you have sideEffects in package.json |
I changed transform and transformIgnorePatterns in jest.config.js and fixed the problem:
It was not sufficient for me to change only transformIgnorePatterns. |
So this cannot be used without babel?? |
With the Vue CLI 4 typescript project:
|
Thsnks for the solution!!! |
Changing my .babelrc to babel.config.js with:
got it working. Make sure to include that along with the jest config updates mentioned above. |
I experienced exactly that problem. I tried everything proposed in this thread as well as most of the stuff google found for me. After 2 hours of vain attempts, I got sick of the problem and switched to vuelidate, even though I find it much less elegant. It's really annoying, because vee-validate works fine in my storybook, it works fine in the application, but for some annoying reason, it doesn't work with jest. |
Same as @zadigus above, I tried everything and almost gave up but I went up with the following solution (with vee-validate 3.1):
No need for |
@logaretm This must be added to the docs of vee-validate, as so many people are using babel transformations and have exactly the same issue. |
@dmitry I added a note to the docs, thank you |
Thanks, this does work but I'm now having issues with Typescript : EDIT: follow this article if you're using Nuxt https://medium.com/@yusufznl/how-to-validate-forms-in-nuxt-with-vee-validate-eef45508c3d4 |
Versions
Describe the bug
I've seen that this issue has already been opened for Nuxt (#2282, #2249, #2240) and that the solution in that case is documented. But I encounter it in a vue-cli app, using TS and Jest,
and I struggled to make it work.
To reproduce
Steps to reproduce the behavior:
throws:
I tried to tweak
jest.config.js
but I'm still running into the issue...I tried several approches from jestjs/jest#2550 without success.
Do you have a working configuration for this use-case?
If so, it would be great to add it to the documentation.
(But TBH it would be better to change the
rules.js
packaging to make the issue go away, and avoid contorsions with build/testing tools)The text was updated successfully, but these errors were encountered: