While building the app, I encounter the warning from 3rd party lib as below:
warn - ./node_modules/follow-redirects/debug.js
Module not found: Can't resolve 'debug' in 'G:\Workspace\node\MERN\client\node_modules\follow-redirects'
Did you mean './debug'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
My stack :
"dependencies": {
"@fortawesome/fontawesome-free": "^6.2.1",
"axios": "^1.2.2",
"bootstrap": "^5.2.3",
"mdb-ui-kit": "^6.0.1",
"next": "^13.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-toastify": "^9.1.1"
}
Content of the debug.js within follow-redirects:
var debug;
module.exports = function () {
if (!debug) {
try {
/* eslint global-require: off */
debug = require("debug")("follow-redirects");
}
catch (error) { /* */ }
if (typeof debug !== "function") {
debug = function () { /* */ };
}
}
debug.apply(null, arguments);
};
And import within index.js file:
var url = require("url");
var URL = url.URL;
var http = require("http");
var https = require("https");
var Writable = require("stream").Writable;
var assert = require("assert");
var debug = require("./debug");
I've checked they repo and issues but apparently no one has ever reported it so I wonder whether it has to do with my specific setup?
I've also tried to remove node_modules and reinstall all dependencies via npm with no luck.
This is normal behavior for the follow-redirects package.
The debug.js file does the following:
debug npm package.debug variable.The code was designed to work with the debug npm package for NodeJs, but this was intended to be optional.
See: https://www.npmjs.com/package/debug
Problems:
debug repeatedly around the code is confusing. There are 3 different debug references, the debug.js file in the follow-redirects, the debug module variable within that file and the debug npm package (that is not installed).The follows-redirect lists debug as an optional peer dependency:
"peerDependenciesMeta": {
"debug": {
"optional": true
}
},
The warning you see:
Module not found: Can't resolve 'debug' in 'G:\Workspace\node\MERN\client\node_modules\follow-redirects'
Is from NextJs and it's being reported for compiling the server side code because it seems like a failure of NodeJs to resolve the package.
How follow-redirects checks for the use of the debug package is a code smell. It should be a user configurable feature, and not something forced on just because a npm package was installed as a peer dependency, or lazy require() and catching an error.
You have the option to install debug and use the feature which fixes the warning.
npm install debug
Alternatively, just ignore the warning. There is no harm in doing so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With