Skip to content
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

Update README to instruct how to alias the native one (due to Node 22 annoying warning) #137

Open
agalatan opened this issue Sep 4, 2024 · 6 comments

Comments

@agalatan
Copy link

agalatan commented Sep 4, 2024

  • Node 22 will start showing warnings that punycode is deprecated, and a userland solution must be used
  • Lots of 3rd party node_modules use native punycode and many are out of our control. It's too many. Especially because node-fetch depends on punycode, and even if this itself is now native .... we all know what a chaos is in node_modules.
  • Anyway, what I did, was to install module-alias and then add before anything else (node -r or via NODE_OPTIONS):
const moduleAlias = require('module-alias');
moduleAlias.addAlias('punycode', 'punycode/');

And it works.
I recommend adding this in the README. I can do it, if I know you will accept it.

@mathiasbynens
Copy link
Owner

Nowadays we publish the package both as punycode and as punycode.js — so the simpler solution is to npm install punycode.js and require('punycode.js') instead. I’d welcome a README patch that mentions these options!

@agalatan
Copy link
Author

agalatan commented Sep 4, 2024

You can't in 3rd party modules, that are deep inside your node_modules, that's my point. You have very little control on the require. And there's plenty of them.

node-fetch brings whatwg-url which:

(node:4994) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:399:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:338:10)
    at loadBuiltinModule (node:internal/modules/helpers:108:7)
    at Function.Module._load (node:internal/modules/cjs/loader:1099:17)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (/Users/alingalatan/workspaces/apap/node_modules/node-fetch/node_modules/whatwg-url/lib/url-state-machine.js:2:18)

Say you got rid of node-fetch:

(node:5235) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    at node:punycode:3:9
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:399:7)
    at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:338:10)
    at loadBuiltinModule (node:internal/modules/helpers:108:7)
    at Function.Module._load (node:internal/modules/cjs/loader:1099:17)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (/Users/alingalatan/workspaces/apap/node_modules/tr46/index.js:3:16)

Now it's tr46

It just keeps going. punycode is present in many node_modules, some not very maintained.

@service-inspectech
Copy link

Seriously good grief, who started this insanity? Getting this deprecation warning removed is near impossible from the amount of usage.

@agalatan
Copy link
Author

@CodeForcer
Copy link

The amount of packages which rely on this is insane. Getting rid of this warning almost brought me to tears

dacarson added a commit to naofireblade/homebridge-weather-plus that referenced this issue Dec 4, 2024
#303 Fix punycode warning. Used fix recommended in mathiasbynens/punycode.js#137
Danimal4326 pushed a commit to Danimal4326/homebridge-weather-plus that referenced this issue Dec 20, 2024
naofireblade#303 Fix punycode warning. Used fix recommended in mathiasbynens/punycode.js#137
Danimal4326 added a commit to Danimal4326/homebridge-weather-plus that referenced this issue Dec 20, 2024
* Fix threshold triggers

naofireblade#296  Fix issue with threshold triggers and WeatherUnderground. In 3.3.4, WeatherUnderground API call was modified and incorrectly return values in km, and km/h

* Fix punycode warning

naofireblade#303 Fix punycode warning. Used fix recommended in mathiasbynens/punycode.js#137

* Fix util._extend warning

Fix naofireblade#303  Though I could not reproduce the warning, this should fix it.

* Migrate off request package

naofireblade#150  Migrate off the deprecated request package and moved all URL loads to using the supported axios package. Tried to make as smaller changes as possible.
Added a little more failure logging to enable better debugging.

Found that punycode was only being used by request so I could remove the work around for it (naofireblade#303)
Found that debug package wasn't explicitly being listed as a dependency in package.json, though index.js requires it, so added that.

Tested with valid tokens - all worked (only tested openweathermap 2.5 API)
Tested with invalid tokens - got correct error messages, didn’t crash HomeBridge
Tested with bad URLs - got correct error messages, didn’t crash HomeBridge

Migrated weewx weather station, though I wasn’t able to test it.

* Update CHANGELOG.md

naofireblade#150 Update Changelog

* Changes for Homebridge 2.0

naofireblade#301 Initial fixes to make the plugin work with Homebridge 2.0
Two basic changes:
1. Use of enums off the Characteristic class is no longer supported:
Instead of const Units = Characteristic.Units; you will need to use const Units = api.hap.Units;
Instead of const Formats = Characteristic.Formats; you will need to use const Formats = api.hap.Formats;
Instead of const Perms = Characteristic.Perms; you will need to use const Perms = api.hap.Perms;

2. Change custom characteristics to be classes with constructors, rather than using the inherits() functionality.

* Change colons for Modifier Letter Triangular Colon

naofireblade#301 Homekit has special rules for naming items. They must start with an alpha or numeric value, then they can contain alphanumeric characters, space and apostrophe, and they must end with an alpha or numeric character. The created sensors are using colons for delimiters, which isn't allowed. However, according to Apple documentation alphanumeric characters consist of Unicode character sets L*, M* and N*. The Modifier Letter Triangular Colon falls into the L* set, so it should be legal to use.
See homebridge/HAP-NodeJS#1079 for more detail.

---------

Co-authored-by: dacarson <[email protected]>
@dan-garden
Copy link

Why is this still a thing in 2025? I'm sick of seeing these errors.

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

5 participants