-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
replace node-fetch with native fetch module (coming with node v18) #2649
Comments
Thanks for the investigation. I agree to keep v2. |
@khassel I had a look into your MR. I'm not sure why we spin up the full electron app for those tests. It should be sufficient there to only run in server mode only. I applied your recent changes from https://github.com/MichMich/MagicMirror/pull/2655/files to your branch I added the import Changed the
I received the error:
Therefore I also applied the moduleNameMapping in the Then I got I'm not sure who would trigger the default, so I added a default to the However, it still complains about default is not a function. Any ideas on how to fix the logger import? |
First of all I'm not very familiar with these e2e tests.
agree to minimize use of e2e
can reproduce this, but I think this error message is misleading because of the following lines: TypeError: logger_1.default is not a function
at Object.<anonymous> (node_modules/@wdio/utils/build/initialiseServices.js:9:29)
at Object.<anonymous> (node_modules/@wdio/utils/build/index.js:9:30) The error is related to |
Tested with the current Added moduleNameMapper to the e2e section in "moduleNameMapper": {
"logger": "<rootDir>/js/logger.js",
"node_helper": "<rootDir>/js/node_helper.js"
}, Changed the const fetch = require("node-fetch");
const app = require("../../js/app.js");
describe("Vendors", function () {
beforeAll(function () {
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
app.start();
});
afterAll( function () {
app.stop();
});
describe("Get list vendors", function () {
const vendors = require(__dirname + "/../../vendor/vendor.js");
Object.keys(vendors).forEach((vendor) => {
it(`should return 200 HTTP code for vendor "${vendor}"`, function (done) {
const urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
fetch(urlVendor).then((res) => {
expect(res.status).toBe(200);
done();
});
});
});
Object.keys(vendors).forEach((vendor) => {
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, function (done) {
const urlVendor = "http://localhost:8080/" + vendors[vendor];
fetch(urlVendor).then((res) => {
expect(res.status).toBe(404);
done();
});
});
});
});
}); Executing this test with But running with node-fetch v3 I'm getting again a segmentation fault. Edit: Its running with v3 using So this is may no solution for the node-fetch upgrade but I will check which other e2e tests could be run with this method which means without the electron/spectron stuff. |
I created a PR #2750. Since I also tested the |
Oh, I missed that @khassel already tested the alternative syntax 😑 So this is not a step forward, sorry. |
problems are the tests, mm itself is running with this change but the tests are failing with a segmentation fault, e.g. Seems to be a node issue so we may have to wait until that is fixed on their side. |
Okay, I don't think there is an urgent need for us to upgrade now. Should I close my PR? |
I did the same work already in September ;) but decided not to create a PR. If you want to leave your PR open you can look into mine to solve the lint problem (instead of ignoring the files) and I also had to change the |
I'll leave my PR open, if it bothers someone, we can of course close it. I have started to replace |
you could convert it to draft so it is clear that it should not merged at the moment |
inspired of your answer I did this yesterday in my module MMM-RepoStats, here the diffs. Beside this is working in the module I think it is no good idea to do this here. I ran in 2 problems
In my case this is not problematic because the url's are fix but in mm the url's for calendar or newsfeed are defined by the user. Therefore, I consider a well-maintained package like |
I'm not sure if it's worth bringing this up here or on another ticket, but moving from My suggestion would be to enhance node_helper with some async functions to aid in basic REST functionality. What that interface looks like, however, I'm not really sure. In that case, rather than having to invoke the library directly, third party devs can use the This would allow third party devs to use node helper for data retrieval, and allow core devs some ability to ensure consistency in error handling during data retrieval. Also, for what it's worth, I'd be willing to put some time into both an ES module migration and a typescript migration, but would probably need the help of those familiar with the nitty-gritty to get in there without messing too much up. |
this is only correct for those modules, which didn't define their dependencies in a
see my comment above "no good idea" ...
we can discuss this but @MichMich is the one who decides this, so I would wait for his statement before someone begins with coding. |
@khassel I don't plan on doing anything without consulting.. it's definitely an expanded use of the node_helper which may add unnecessary overhead to non-data plugins. While the module development section on the website outlines how to use native modules, it doesn't really explicitly say "Don't use modules that we already use" and, because of how JS is loading modules, if it's there, it can be used. Perhaps something as simple as a nice large warning for module devs to warn them to always install the packages they need via their own packages.json and to not assume packages and versions within magicmirror will be available. |
What do you think about using I think it is better than continuing to use |
Are there any features in v3 that are missing for use in this project? The node-fetch team still provides fixes for the v2 of the module. The nodejs team also announced that they implement fetch as a native module in the next LTS version 18 nodejs/node#41749 which can already be used with the experimental flag. I'm not sure if it is worth it to switch now to another module without a need instead of updating v2 with the fixes and then switching for the native module. |
That fetch becomes a native module in nodejs was news to me. Thanks! I think we can wait for that and as you suggested then switching to the native module 🙂 |
Will take a while until node 18 will be the minimum version for MM² but I agree, until then we can use v2 of the library |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
should not be closed. |
If you remove const fetch = require("node-fetch"); It is understandable (and desirable) to continue to upgrade as new functionality becomes available. My only ask is that, if and when these types of changes occur, some effort is made in either the forums or discord (or both) to notify module developers of the changes, it will be helpful in order to update our modules to be compatible. That said, given that the http fetch functionality seems to be very common but also constantly changing, does it make sense to extend the node_helper.js class to include a fetch function or, at the least, return a known fetch client that would allow us to retrieving data via http calls? Would the community consider, perhaps, using a different third party library (such as Axios) as the default within the node helper? I understand the desire to allow module developers the ability to use their own libraries/make their own calls, but it would seem some modules have been built to utilize modules installed by MagicMirror Core. This can present difficulties, particularly during troubleshooting, because every module does things differently, with some self-contained (not using dependencies from the core) and others not self-contained. I'd certainly be willing to give this type of change a go. |
sorry for the late reply.
at the moment we have to stay with
we can do this (if we switch in the future) but this will reach only a few active developers. We had already such a situation when we removed
we have already such a fetch function in
I don't see anything we can do to prevent this ... |
one should note that developers 'utilize modules installed by MagicMirror Core.' is because we don't have professional developers and they are cloning the default modules and re-using the code.. this is a good OS model. i have added code to my upgrade script to try to address the modules where developers didn't know about package.json (as it wasn't needed for default modules) etc,etc,etc.. part of the lifecycle
|
related to #2649 I was able to move to internal fetch and all tests seems fine so far. But we have one problem with the calendar module. In the docs we have several authentication methods and one of them is `digest`. For this we used `digest-fetch` which needs `node-fetch` (this is not so clear from code but I was not able to get it working). So we have 3 options: - remove `digest` as authentication method for calendar module (this is what this PR does at the moment) - find an alternative npm package or implement the digest stuff ourselves - use `digest-fetch` and `node-fetch` for calendar module (so they would remain as dependencies in `package.json`) Opinions? @KristjanESPERANTO @rejas @sdetweil @MichMich
## [2.25.0] - 2023-10-01 Thanks to: @bugsounet, @dgoth, @dependabot, @kenzal, @Knapoc, @KristjanESPERANTO, @martingron, @NolanKingdon, @Paranoid93, @TeddyStarinvest and @Ybbet. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! >⚠️ This release needs nodejs version >= `v18`, older releases have reached end of life and will not work! ### Added - Added UV Index support to OpenWeatherMap - Added 'hideDuplicates' flag to the calendar module - Added `allowOverrideNotification` to weather module to enable sending current weather objects with the `CURRENT_WEATHER_OVERRIDE` notification to supplement/replace the current weather displayed - Added optional AnimateCSS animate for `hide()`, `show()`, `updateDom()` - Added AnimateIn and animateOut in module config definition - Apply AnimateIn rules on the first start - Added automatic client page reload when server was restarted by setting `reloadAfterServerRestart: true` in `config.js`, per default `false` (#3105) - Added eventClass option for customEvents on the default calendar - Added AnimateCSS integration in tests suite (#3206) - Added npm dependabot [Reserved to developer] (#3210) - Added improved logging for calendar (#3110) ### Removed - **Breaking Change**: Removed `digest` authentication method from calendar module (which was already broken since release `2.15.0`) ### Updated - Update roboto fonts to version v5 - Update issue template - Update dev/dependencies incl. electron to v26 - Replace pretty-quick by lint-staged (<prettier/pretty-quick#164>) - Update engine node >=18. v16 reached it's end of life. (#3170) - Update typescript definition for modules - Cleaned up nunjuck templates - Replace `node-fetch` with internal fetch (#2649) and remove `digest-fetch` - Update the French translation according to the English file. - Update dependabot incl. vendor/fonts (monthly check) - Renew `package-lock.json` for release ### Fixed - Fix engine check on npm install (#3135) - Fix undefined formatTime method in clock module (#3143) - Fix clientonly startup fails after async added (#3151) - Fix electron width/heigth when using xrandr under bullseye - Fix time issue with certain recurring events in calendar module - Fix ipWhiteList test (#3179) - Fix newsfeed: Convert HTML entities, codes and tag in description (#3191) - Respect width/height (no fullscreen) if set in electronOptions (together with `fullscreen: false`) in `config.js` (#3174) - Fix: AnimateCSS merge hide() and show() animated css class when we do multiple call - Fix `Uncaught SyntaxError: Identifier 'getCorsUrl' has already been declared (at utils.js:1:1)` when using `clock` and `weather` module (#3204) - Fix overriding `config.js` when running tests (#3201) - Fix issue in weathergov provider with probability of precipitation not showing up on hourly or daily forecast --------- Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Malte Hallström <46646495+SkySails@users.noreply.github.com> Co-authored-by: Veeck <github@veeck.de> Co-authored-by: veeck <michael@veeck.de> Co-authored-by: dWoolridge <dwoolridge@charter.net> Co-authored-by: Johan <jojjepersson@yahoo.se> Co-authored-by: Dario Mratovich <dario_mratovich@hotmail.com> Co-authored-by: Dario Mratovich <dario.mratovich@outlook.com> Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com> Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: buxxi <buxxi@omfilm.net> Co-authored-by: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com> Co-authored-by: Dave Child <dave@addedbytes.com> Co-authored-by: grenagit <46225780+grenagit@users.noreply.github.com> Co-authored-by: Grena <grena@grenabox.fr> Co-authored-by: Magnus Marthinsen <magmar@online.no> Co-authored-by: Patrick <psieg@users.noreply.github.com> Co-authored-by: Piotr Rajnisz <56397164+rajniszp@users.noreply.github.com> Co-authored-by: Suthep Yonphimai <tomzt@users.noreply.github.com> Co-authored-by: CarJem Generations (Carter Wallace) <cwallacecs@gmail.com> Co-authored-by: Nicholas Fogal <nfogal.misc@gmail.com> Co-authored-by: JakeBinney <126349119+JakeBinney@users.noreply.github.com> Co-authored-by: OWL4C <124401812+OWL4C@users.noreply.github.com> Co-authored-by: Oscar Björkman <17575446+oscarb@users.noreply.github.com> Co-authored-by: Ismar Slomic <ismar@slomic.no> Co-authored-by: Jørgen Veum-Wahlberg <jorgen.wahlberg@amedia.no> Co-authored-by: Eddie Hung <6740044+eddiehung@users.noreply.github.com> Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr> Co-authored-by: bugsounet <bugsounet@bugsounet.fr> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Knapoc <Knapoc@users.noreply.github.com> Co-authored-by: sam detweiler <sdetweil@gmail.com> Co-authored-by: veeck <michael.veeck@nebenan.de> Co-authored-by: Paranoid93 <6515818+Paranoid93@users.noreply.github.com> Co-authored-by: NolanKingdon <27908974+NolanKingdon@users.noreply.github.com> Co-authored-by: J. Kenzal Hunter <kenzal.hunter@gmail.com> Co-authored-by: Teddy <teddy.payet@gmail.com> Co-authored-by: TeddyStarinvest <teddy.payet@starinvest.com> Co-authored-by: martingron <61826403+martingron@users.noreply.github.com> Co-authored-by: dgoth <132394363+dgoth@users.noreply.github.com>
We are using
node-fetch
for fetching url's in 3 places:With the new version v3 they decided to convert
node-fetch
to ES module so we can not userequire
anymore. I testet the alternative syntax usingconst fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
instead.The modules calendar and newsfeed are working with this change, but
jest
is failing with aSegmentation fault
:PID 2750 received SIGSEGV for address: 0x10 /opt/magic_mirror/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x3206)[0x7f18049f3206] /lib/x86_64-linux-gnu/libpthread.so.0(+0x12730)[0x7f18046b9730] node[0xa15ec0] node(_ZN2v88internal7Isolate38RunHostImportModuleDynamicallyCallbackENS0_6HandleINS0_6ScriptEEENS2_INS0_6ObjectEEENS0_11MaybeHandleIS5_EE+0xad)[0xe4bb5d] node(_ZN2v88internal25Runtime_DynamicImportCallEiPmPNS0_7IsolateE+0xb1)[0x11fd7d1] node[0x15ce134]
AFAIS this error comes from the headless chromium browser used for the e2e tests.
At this point I stopped my PR for using
node-fetch
v3. They still support v2 with security patches, so we have no problem yet.For the future we need a solution for this or have to use antoher library.
In
package.json
node-fetch
must stay on v2.The text was updated successfully, but these errors were encountered: