Versions
Describe the bug
When I try to import the "required" rule inside a Nuxt.js plugin, I am receiving a Unexpected token export error. If I comment out the "required" import or the "required" extend lines, the issue go away.
Customer Nuxt.js Plugin Code
import Vue from 'vue';
import { ValidationProvider, extend, configure } from 'vee-validate';
import { required } from 'vee-validate/dist/rules';
extend('required', required);
configure({
classes: {
invalid: 'is-danger'
}
});
Vue.component('ValidationProvider', ValidationProvider);
I don't know why...for now
nuxt.config.js
module.exports = {
build: {
transpile: [
'vee-validate'
]
}
}
Everything is thoroughly explained in documentation, including the error that occurs and the correct integration.
Link: https://baianat.github.io/vee-validate/examples/nuxt.html
Thank you @ririen for linking the documentation. Closing...
@ririen The link doesn't work anymore.
Also found this one: https://logaretm.github.io/vee-validate/examples/nuxt.html
Both links are broken at the moment. I've done my homework and researched the solution in the project history. Adding the solution here because links cannot be trusted.
"vee-validate/dist/rules" needs to be added to the transpile item in the build key of the nuxt.config.js file.
build: {
// Add exception
transpile: [
"vee-validate/dist/rules"
],
/*
** You can extend webpack config here
*/
extend(config, ctx) {}
}
The docs were re-structured recently, there is the new link:
https://logaretm.github.io/vee-validate/guide/rules.html#importing-rules-in-nuxt-js
Most helpful comment
Both links are broken at the moment. I've done my homework and researched the solution in the project history. Adding the solution here because links cannot be trusted.
"vee-validate/dist/rules"needs to be added to thetranspileitem in thebuildkey of the nuxt.config.js file.