docker-js icon indicating copy to clipboard operation
docker-js copied to clipboard

Undefined returned from homedir() call passed unto path.join at top level

Open whizyrel opened this issue 4 years ago • 6 comments

My issue exactly: I am using this module on a NodeJS Server and I get this error TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at validateString (internal/validators.js:124:11) at Object.join (path.js:1039:7) at eval (webpack://mms-frontend-service/./node_modules/mydockerjs/lib/utils.js?:14:26) I am using this on Linux so, I maybe understand why this happened on this line. Please check this out, also I would submit a PR of the fix for the sake of linux users.

whizyrel avatar Apr 24 '21 06:04 whizyrel

Hi @whizyrel , could you give me more information about the nodejs version , homedir version and used operating system when the issue occurred? Which user is running the code? If you understand the issue, could you give me more details please ? Thank you

giper45 avatar Apr 24 '21 06:04 giper45

NodeJS: 14.16.0 Homedir: 0.6.0 OS: Ubuntu 20.04 LTS User: non-root user

Thank you for your quick response. Like I said I am running a NodeJS server where I am using this module. I get that TypeError because homedir() returns undefined like so path.join(homedir(), ...) on line 13. It also seem like a issue from homedir() since it is supposed to return the user home path on LInux and Windows.

whizyrel avatar Apr 24 '21 06:04 whizyrel

Ok, I think that this is related with an external library, homedir. https://github.com/wilmoore/node-homedir/blob/master/index.js If you look at the code, the module tries to get home path by using HOME environment variable: image

Could you check if your username has env HOME defined? echo $HOME

giper45 avatar Apr 24 '21 06:04 giper45

In any case, this is related with toolboxPath, a variable that I never use in the code, as I was trying to implement windows docker toolbox support, but I unfortunately did not have too much time to implement it :-). As it is used for Windows purposes, we can check if the process platform is win32 and use it only if it is the case.

giper45 avatar Apr 24 '21 06:04 giper45

If you are able to pull request me this fix, I really appreciate it. Thank you

giper45 avatar Apr 24 '21 06:04 giper45

Yes, I mentioned it seem like a homedir bug caused it, and it does have a $HOME defined. I figured process.env['HOME'] does return the path when it is not running as a server otherwise it returns undefined. While it seem like a homedir issue, it actually is not. So, I use webpack and did not include all of the env vars completely only those I defined. To solve this issue when someone else does the same thing I did, I could PR. Also, an example of including all env vars in webpack config would be using EnvironmentPlugin and not DefinePlugin which is a popular choice An example Webpack issue

...
plugins: [
   new webpack.EnvironmentPlugin([...Object.keys(process.env)])
]
...

Let me know what you think

whizyrel avatar Apr 24 '21 08:04 whizyrel