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

Deprecation Warning: The util.isArray API is deprecated. Please use Array.isArray() instead. #56

Open
Hari-Shankar-Karthik opened this issue May 24, 2024 · 4 comments

Comments

@Hari-Shankar-Karthik
Copy link

To the devs of connect-flash,

In my nodejs project, I used connect-flash to display messages like 'Comment created successfully', etc. when I got the following warning:

(node:4588) [DEP0044] DeprecationWarning: The util.isArray API is deprecated. Please use Array.isArray() instead.

The stacktrace tells me it originated from connect-flash\lib\flash.js:67:16 when I used node --trace-deprecation

Kindly change it as soon as possible.

Thank you!

@kukielski
Copy link

kukielski commented Aug 10, 2024

@Hari-Shankar-Karthik
I went into node_modules/connect-flash/lib/flash.js
Then I changed the line: var isArray = require('util').isArray;

to: var isArray = Array.isArray;

I know next to nothing in coding, but now the deprecation error went away for me. Not sure if this is the right solution, as I am still new to all this, but again, I don't have an error any longer.

@ecofi
Copy link

ecofi commented Sep 23, 2024

+1

@Freezler
Copy link

And how do you keep the changes from being overwritten when you delete your lock file and node_modules and do a install again?
Not that it a lot of work to corrwet it but in the spirit of not repeating to much i'm wondering
what could be a solution to this.. I made an .md with my own solution. but it was not well recieved and was told it was solvable in just 2 lines of code.

figured that part out but how do i make the change permanent?

thanks in advance!

@YasharF
Copy link

YasharF commented Jan 23, 2025

As a temporary workaround you can use a patch file.

  1. Add patch-package to your project by npm install patch-package --save.
  2. Add "postinstall": "patch-package" to the"scripts" section of your package.json.
  3. Create a patches folder in your project and add the following as a file named connect-flash+0.1.1.patch in there.
  4. Rerun npm install.
diff --git a/node_modules/connect-flash/lib/flash.js b/node_modules/connect-flash/lib/flash.js
index a278bc1..3870866 100644
--- a/node_modules/connect-flash/lib/flash.js
+++ b/node_modules/connect-flash/lib/flash.js
@@ -2,7 +2,6 @@
  * Module dependencies.
  */
 var format = require('util').format;
-var isArray = require('util').isArray;
 
 
 /**
@@ -64,7 +63,7 @@ function _flash(type, msg) {
     if (arguments.length > 2 && format) {
       var args = Array.prototype.slice.call(arguments, 1);
       msg = format.apply(undefined, args);
-    } else if (isArray(msg)) {
+    } else if (Array.isArray(msg)) {
       msg.forEach(function(val){
         (msgs[type] = msgs[type] || []).push(val);
       });

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