You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The latest vee-validate version uses the exports field to declare its entry points. Our project uses ESM and loaded vee-validate as ESM with the previous version. With the latest version we get the following error however:
Named export 'configure' not found. The requested module 'vee-validate' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using: import pkg from 'vee-validate'; const { useForm, configure, defineRule, useField } = pkg;
I believe this issue is caused by a combination of various factors:
exports declaration always have priority over other package.json properties like "main" or "module".
exports declarations do not declare the format of the target file. they only target how the package was loaded (e.g. by require or import)
all vee-validate files use the .js file extension, regardless of whether they are in CJS or ESM format
vee-validate does not specify a "type" in package.json
therefore, the .js files are treated as CJS, even if they are ESM files
This is in contrast to the previous version, where the "module" property implicitly marks the target as being an ESM file.
I believe the correct solution is to specify a default type in the "type" field and use explicit file extensiosn (.cjs, .mjs) for the other type. This approach is also documented on the official NodeJS documentation: https://nodejs.org/api/packages.html#dual-commonjses-module-packages
What happened?
The latest vee-validate version uses the exports field to declare its entry points. Our project uses ESM and loaded vee-validate as ESM with the previous version. With the latest version we get the following error however:
Named export 'configure' not found. The requested module 'vee-validate' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using: import pkg from 'vee-validate'; const { useForm, configure, defineRule, useField } = pkg;
I believe this issue is caused by a combination of various factors:
This is in contrast to the previous version, where the "module" property implicitly marks the target as being an ESM file.
I believe the correct solution is to specify a default type in the "type" field and use explicit file extensiosn (.cjs, .mjs) for the other type. This approach is also documented on the official NodeJS documentation: https://nodejs.org/api/packages.html#dual-commonjses-module-packages
Further resources:
https://stackoverflow.com/a/77287842
https://nodejs.org/api/esm.html#modules-ecmascript-modules
https://nodejs.org/api/packages.html#dual-commonjses-module-packages
Reproduction steps
...
Version
Vue.js 3.x and vee-validate 4.x
What browsers are you seeing the problem on?
Relevant log output
No response
Demo link
none
Code of Conduct
The text was updated successfully, but these errors were encountered: