Skip to content

Documentation Issue: Incorrect ES Import Path #2528

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

Open
saar-twito opened this issue Feb 9, 2025 · 3 comments
Open

Documentation Issue: Incorrect ES Import Path #2528

saar-twito opened this issue Feb 9, 2025 · 3 comments
Labels

Comments

@saar-twito
Copy link

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).

@WikiRik
Copy link
Member

WikiRik commented Feb 10, 2025

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?

@gordonscott08
Copy link

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('example@example.com'));`

@critesjm
Copy link

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').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants