Skip to content

Fix punycode deprecation warning #876

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

Closed
cozykitten opened this issue Jan 20, 2024 · 7 comments
Closed

Fix punycode deprecation warning #876

cozykitten opened this issue Jan 20, 2024 · 7 comments

Comments

@cozykitten
Copy link

Tesseract.js version (version number for npm/GitHub release, or specific commit for repo)
5.0.4

Describe the bug
When updating to node v21 this node warning comes up when using packages that rely on node's built in punycode module.
(node:15352) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.

This module can be traced back to an old version of tr46 which itself is used in an old version of whatwg-url which itself is used in an old version of node-fetch.
tr46 already fixed that issue and newer versions of whatwg-url don't have the same issue and as far as I can tell the latest node-fetch version doesn't even use whatwg-url in the first place.

Long story short, would you consider updating to a newer version of node-fetch?

To Reproduce
Steps to reproduce the behavior:

  1. Update node to v21
  2. run project using tesseract.js
  3. See error

Device Version:

  • OS + Version: Windows 11 22H2
  • Node v21.6
@Balearica Balearica changed the title regarding the punycode deprecation warning Fix punycode deprecation warning Jan 22, 2024
@Balearica
Copy link
Member

Thanks for looking into this. I looked into whether it is possible to remove this warning message by bumping the version of node-fetch, however I do not believe it is. Tesseract.js uses v2 of node-fetch.

  1. According to this issue, the depreciation warning is still an issue for the latest v2 release of node-fetch
  2. According to this documentation, using v3 of node-fetch would not be possible without adapting the project to use ESM modules rather than CommonJS
    1. The documentation states "We recommend you stay on v2 which is built with CommonJS unless you use ESM yourself. We will continue to publish critical bug fixes for it."

Therefore, I believe this warning will continue until either (1) there is v2 release of node-fetch that resolves it or (2) Tesseract.js switches to ESM modules. The latter will probably happen in the next major version, however is currently not a priority for me.

@cozykitten
Copy link
Author

Thank you, next major version sounds good enough.
For now I fixed it manually by going down the module tree and modifying the old version of tr46 and whatwg-url directly to use the userland punycode module.

@Balearica
Copy link
Member

Interestingly, it looks like a stable version of fetch has been added to Node.js before either (1) node-fetch releases a version of v2 without this issue or (2) the Node.js community switches to ESM. Therefore, I think the solution to this may just be to use node-fetch as a polyfill for old Node.js versions and tell people annoyed by the warning message to upgrade.

@Balearica
Copy link
Member

Reopening as this issue is not yet resolved. Will close once this has been patched.

@Balearica Balearica reopened this Apr 4, 2025
@Balearica
Copy link
Member

There is some conflicting information regarding when fetch was added to Node.js, which is likely attributable to LLMs being used in search results. To summarize what I found:

  1. fetch was added behind an experimental flag (--experimental-fetch) in Node.js v17.5.0
  2. fetch was included by default, however still flagged as experimental, in Node.js v18.0.0
  3. fetch was marked as stable in v21.0.0

Tesseract.js currently supports Node.js v14 and higher. Therefore, it looks like the only versions that require node-fetch are v14 (reached end-of-life on April 30, 2023) and v16 (reached end-of-life on September 11, 2023).

@cozykitten
Copy link
Author

Yea, I remember using fetch since v18 and never had an issue with it

@Balearica
Copy link
Member

Closing as this was implemented in v6.0.1, which is now live on npm.

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

No branches or pull requests

2 participants