Documentation Issue: Incorrect ES Import Path
The documentation on npm indicates that tree-shakeable ES imports should be done using: import isEmail from 'validator/es/lib/isEmail.js'. However, the es folder does not exist in the package. Only the path validator/lib/isEmail.js works.
Either the es folder should exist to support ES imports as documented, or the documentation should be updated to reflect the correct import path (validator/lib/isEmail.js).
If I'm looking through the published files in NPM, I do see that file. It's not in the repo since it's generated upon preparing a release. What is the error you are getting?
Noting the error messages received when using ES import syntax from the documentation.
To reproduce: Node 22.x, NPM 10.x, validator: 13.15.0, package.json.type: module.
//import isEmail from 'validator/lib/isEmail'; // Documentation example 1. Throws error snippet below. Cannot find module '{...}/validator/node_modules/validator/lib/isEmail' imported from {...}/validator/app.js
Did you mean to import "validator/lib/isEmail.js"?`
//import isEmail from 'validator/es/lib/isEmail'; // Documentation example 2. Throws error snippet below.
Cannot find module '{...}/validator/node_modules/validator/es/lib/isEmail' imported from {...}/validator/app.js Did you mean to import "validator/es/lib/isEmail.js"?
import isEmail from 'validator/lib/isEmail.js'; // Refactor with js extension. Works.
// import isEmail from 'validator/es/lib/isEmail.js'; // Refactor 2 with js extension. Throws error snippet below.
Cannot find module '{...}/validator/node_modules/validator/es/lib/util/assertString' imported from {...}/validator/node_modules/validator/es/lib/isEmail.js
console.log(isEmail('[email protected]'));`
I can confirm the same behavior and will add that I get some sort of error no matter how I import the library unless I use the ES6 default import style (import v from 'validator').
node esm required to have extensions. that why
import 'isEmail' from 'validator/es/lib/isEmail.js'
try to works. But internal imports should be done with extensions too and hat not happens on file inself.
So build system should be adjust before using esm on nodejs
Same here, cannot make it work with the syntax import isUUID from 'validator/es/lib/isUUID.js' provided in the README. Only default import works import validator from 'validator'
Yeah, the problem is that the package internally doesn't use file extensions, and Node ESM imports require it.
I get these errors, (unless I use some sort of bundler to add the file extensions)
Cannot find module /Users/drew/Sites/project/node_modules/validator/es/lib/util/assertString' imported from /Users/drew/Sites/project/node_modules/validator/es/lib/isUUID.js",
It is because the package is missing file extensions of assertString.js for example.
Is this documentation issue or further error, because it seems using:
import from 'validator/es/lib/isAscii' causes errors with vitest when some of dependencies are importing validator this way.
FAIL frontend/src/app/components/domain-list.component.spec.ts [ src/app/components/domain-list.component.spec.ts ]
Error: Cannot find module \frontend\node_modules\validator\es\lib\isAscii' imported from frontend\node_modules\arnes-ui\fesm2022\arnes-ui.mjs
Did you mean to import "validator/es/lib/isAscii.js"?
And then when importing "validator/es/lib/isAscii.js" it doesn't work, another error:
Error: Cannot find module 'frontend\node_modules\validator\es\lib\util\assertString' imported fromfrontend\node_modules\validator\es\lib\isAscii.js
It works only with "validator/lib/isAscii.js"