env-cmd: Not working in Windows 10: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined

Issue: I’'m not able to load any .env/.js file using env-cmd How to reproduce:

  1. install npm install -g env-cmd
  2. create new folder and create .env file and paste below content (taken from example repo)
TEST_NAME=Default File Path Test
NODE_ENV=env-file
ENVVAR=exists
ENV_PATH=./.env
  1. Run command env-cmd in that folder This throws error which is mentioned below:
PS C:\Users\1gour\OneDrive\Documents\old\Github\new> env-cmd
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:112:11)
    at Object.normalize (path.js:266:5)
    at parseNonShell (C:\Users\1gour\AppData\Roaming\nvm\v12.15.0\node_modules\env-cmd\node_modules\cross-spawn\lib\parse.js:49:31)
    at parse (C:\Users\1gour\AppData\Roaming\nvm\v12.15.0\node_modules\env-cmd\node_modules\cross-spawn\lib\parse.js:88:37)
    at Object.spawn (C:\Users\1gour\AppData\Roaming\nvm\v12.15.0\node_modules\env-cmd\node_modules\cross-spawn\index.js:9:20)
    at Object.EnvCmd (C:\Users\1gour\AppData\Roaming\nvm\v12.15.0\node_modules\env-cmd\dist\env-cmd.js:59:26)
    at async Object.CLI (C:\Users\1gour\AppData\Roaming\nvm\v12.15.0\node_modules\env-cmd\dist\env-cmd.js:19:16) {
  code: 'ERR_INVALID_ARG_TYPE'
}

I tried to install it locally instead of globally but still same issue.

Also, If I rename .env to anything else like .env.dev it denies its existence:

PS C:\Users\1gour\OneDrive\Documents\old\Github\new> env-cmd -f .env.dev
Error: Failed to find .env file at default paths: [./.env,./.env.js,./.env.json]
    at getEnvFile (C:\Users\1gour\AppData\Roaming\nvm\v12.15.0\node_modules\env-cmd\dist\get-env-vars.js:58:11)

I’ve also tried using async file i.e. async-env.js but still same issue Failed to find .env file

I’ve tried uninstalling installing again but doesn’t work. I’m not sure if somebody tested this package in Windows or not but I can’t make it work!

Platform: Windows 10 Teminal: Powershell core 6.2.3 (also tried with cmd but same error) “env-cmd”: “^10.1.0”,

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 10
  • Comments: 15

Most upvoted comments

I’m having the same issue, I’ve tried running on both MacOS Catalina 10.15.7 and Ubuntu 20.04. I’ve tried multiple different versions, including all versions from 9.0.0-10.1.0, with the same result:

TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received undefined
    at validateString (internal/validators.js:121:11)
    at normalizeSpawnArguments (child_process.js:411:3)
    at Object.spawn (child_process.js:551:13)
    at Object.spawn (/root/development/labnetic/node_modules/env-cmd/node_modules/cross-spawn/index.js:12:24)
    at Object.<anonymous> (/root/development/labnetic/node_modules/env-cmd/dist/env-cmd.js:57:30)
    at Generator.next (<anonymous>)
    at fulfilled (/root/development/labnetic/node_modules/env-cmd/dist/env-cmd.js:4:58) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Has this been looked into?

@bastiankoetsier

I have same error when I do not specify the executable file.

env-cmd -f .env.development throwing an error, but env-cmd -f .env.development node sample.js work ok

macOS Catalina, Node v14.5.0, env-cmd@10.1.0

Yeah can’t get this working on Big Sur at all 🤷‍♂️

Yeah, same here. Looks like Catalina upgrade broke it. Will have to dump env-cmd from the project now 😦 was great while it lasted

macOS Catalina, Node v10.18.1, env-cmd@10.1.0

For me -f/--file is also throwing an error:

env-cmd -f .env.development 

TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received undefined

macOS Catalina Running on Node v14.0.0 with env-cmd@10.0.1 The file exists in the same directory.

same problem on mac os