dotenvx run doesn't run under powershell
dotenvx -V
1.22.0
This command doesn't run in Powershell:
dotenvx run -f .env.testing -- node index.js
In pwsh:
PS D:\temp> dotenvx run -f .env.testing -- node index.js
[[email protected]] missing node file (D:\temp\node)
? add one with [echo "HELLO=World" > node] and re-run [dotenvx run -- ]
[[email protected]] injecting env (0) from .env.testing, index.js
missing command after [dotenvx run --]
get help: [dotenvx help run]
or try: [dotenvx run -- npm run dev]
If I run it under cmd it runs correctly.
Seems very similar to https://github.com/dotenvx/dotenvx/issues/309
can you check what encoding your .env file has? is it utf8?
-- is a speical token The end-of-parameters token in powershell, so we need to pass -- twice like dotenvx run -f .env.testing -- -- node index.js
It has something todo with dotenvx. Encoding of all files is UTF8
# works
dotenv -e .env.testing -- node index.js
dotenv -e .env.testing node index.js
# doesn't work
dotenvx run -f .env.testing -- node index.js
# works
dotenvx run -f .env.testing -- -- node index.js
See attached zip file for the test setup. I am aware that different console have different "syntax", I am just looking for a syntax that works on pwsh, bash etc..
i see the issue. effort happening here: https://github.com/dotenvx/dotenvx/pull/438
@klodoma and @BingKeh can you try 1.22.2. you should now be able to do:
dotenvx run -f .env.testing -- node index.js
closing but reply here and I'll re-open if problem persists.
The issue is still there, I tried it with 1.22.2 and 1.23.0
PS D:\temp\dotenvx> npm install @dotenvx/[email protected]
up to date, audited 34 packages in 733ms
11 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
PS D:\temp\dotenvx> dotenvx -V
1.22.2
PS D:\temp\dotenvx> dotenvx run -f .env.testing -- node index.js
ambiguous command due to missing '--' separator. try [dotenvx run -f .env.testing -- yourcommand]
PS D:\temp\dotenvx> npm install @dotenvx/[email protected]
changed 1 package, and audited 34 packages in 738ms
11 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
PS D:\temp\dotenvx> dotenvx -V
1.23.0
PS D:\temp\dotenvx> dotenvx run -f .env.testing -- node index.js
ambiguous command due to missing '--' separator. try [dotenvx run -f .env.testing -- yourcommand]
PS D:\temp\dotenvx>
darn. i will get powershell going and will try to duplicate.
in the meantime, can you test if dotenv-cli has the same issue for you:
https://github.com/entropitor/dotenv-cli
dotenv-cli doesn't have the same issue. That's what we're currently using and works well.
i set up a windows machine with powershell and installed dotenvx using winget and I could not duplicate this.
can you share more details about your windows set up and how you are installing dotenvx, please.
I created this repo for testing: https://github.com/klodoma/dotenvx-434
PS D:\temp\dotenvx> npm --version
10.8.2
PS D:\temp\dotenvx> node --version
v20.15.1
Command that fails:
dotenvx run -f .env.testing -- node index.js
If this command is ran as an "npm script" it works. , see below.
Command that works:
dotenv -e .env.testing -- node index.js
npm run ok
npm run ok-x
I use powershell core (installed with scoop) but with the normal powershell I get the same results. Tested this on 2 different PCs, same issue.
I created this repo for testing: https://github.com/klodoma/dotenvx-434
PS D:\temp\dotenvx> npm --version 10.8.2 PS D:\temp\dotenvx> node --version v20.15.1Command that fails:
dotenvx run -f .env.testing -- node index.jsIf this command is ran as an "npm script" it works. , see below.
Command that works:
dotenv -e .env.testing -- node index.jsnpm run oknpm run ok-xI use powershell core (installed with scoop) but with the normal powershell I get the same results. Tested this on 2 different PCs, same issue.
The npm run-script use cmd.exe as default shell in Windows, which won't have issue with -- token. Use Get-Command dotenvx to find out which script file will be used. When invoked with dotenvx.ps1, the -- will be interpreted as a special token, as mentioned above, which casues the command to fail. Try using dotenvx.cmd, and it will work.
thank you. this is very helpful.
a few more bits of information since I think this might be related to npm run and global vs local installs.
is your dotenv-cli (dotenv) also installed globally? can you give me the redacted output of any/all of the following commands:
Get-Command dotenv
where dotenv
npm list -g dotenv-cli
and double checking for dotenvx as well:
Get-Command dotenvx
where dotenvx
npm list -g @dotenvx/dotenvx
this way I can just be sure we are isolating to a local repo install only.
thank you. this is very helpful.
a few more bits of information since I think this might be related to
npm runand global vs local installs.is your dotenv-cli (dotenv) also installed globally? can you give me the redacted output of any/all of the following commands: this way I can just be sure we are isolating to a local repo install only.
I have everything installed locally and not globally. See attached image. Output attached as well.
PS D:\temp\dotenvx> Get-Command dotenv
CommandType Name Version Source
----------- ---- ------- ------
ExternalScript dotenv.ps1 D:\temp\dotenvx\node_modules\.bin\dotenv.ps1
PS D:\temp\dotenvx> where dotenv
PS D:\temp\dotenvx> npm list -g dotenv-cli
C:\Users\andy\scoop\apps\nvm\current\nodejs\nodejs -> .\
└── (empty)
npm notice
npm notice New minor version of npm available! 10.8.2 -> 10.9.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0
npm notice To update run: npm install -g [email protected]
npm notice
PS D:\temp\dotenvx> Get-Command dotenvx
CommandType Name Version Source
----------- ---- ------- ------
ExternalScript dotenvx.ps1 D:\temp\dotenvx\node_modules\.bin\dotenvx.ps1
PS D:\temp\dotenvx> whereis dotenvx
dotenvx: /cygdrive/d/temp/dotenvx/node_modules/.bin/dotenvx /cygdrive/d/temp/dotenvx/node_modules/.bin/dotenvx.cmd /cygdrive/d/temp/dotenvx/node_modules/.bin/dotenvx.ps1
PS D:\temp\dotenvx> npm list -g @dotenvx/dotenvx
C:\Users\andy\scoop\apps\nvm\current\nodejs\nodejs -> .\
└── (empty)
PS D:\temp\dotenvx>
Hi, any progress on this? I have the same issue :(
additional info: https://x.com/Davi_g117/status/1910621858602369312
When passing an argument to the dotenvx run command with PowerShell it gives an error. With the Command Prompt or my Linux (Ubuntu) machine, it works correctly.
It only gives an error when trying to run it with PowerShell.
For example:
dotenvx run -- npm run dev works fine.
dotenvx run -f .env.development -- npm run dev doesn't work and gives an error:
ambiguous command due to missing '--' separator. try [dotenvx run -f .env.development -- yourcommand]
I've managed to work around this bug by typing it like this in PowerShell:
& 'dotenvx' 'run' '-f' '.env.development' '--' 'npm' 'run' 'dev'