deno
deno copied to clipboard
Deno can't find command
I'm trying to use npm @azure/identity (v.3.1.3) with Deno but there is some problem with login to azure when I use AzureCliCredential.
I'm getting this error:
CredentialUnavailableError: '\"az account get-access-token --output json --resource https://vault.azure.net --tenant <myTenant>\"' is not recognized as an internal or external command,
operable program or batch file.
at file:///C:/Users/<user>/AppData/Local/deno/npm/registry.npmjs.org/@azure/identity/3.1.3/dist/index.js:2489:31
at Object.runMicrotasks (deno:core/01_core.js:386:30)
at processTicksAndRejections (https://deno.land/[email protected]/node/_next_tick.ts:62:10)
at async Object.withSpan (file:///C:/Users/<user>/AppData/Local/deno/npm/registry.npmjs.org/@azure/core-tracing/1.0.1/dist/index.js:140:28)
at async tryGetAccessToken (file:///C:/Users/<user>/AppData/Local/deno/npm/registry.npmjs.org/@azure/core-rest-pipeline/1.10.1/dist/index.js:1997:32)
at async beginRefresh (file:///C:/Users/<user>/AppData/Local/deno/npm/registry.npmjs.org/@azure/core-rest-pipeline/1.10.1/dist/index.js:2005:17)
at async Object.authorizeRequestOnChallenge (file:///C:/Users/<user>/AppData/Local/deno/npm/registry.npmjs.org/@azure/keyvault-secrets/4.6.0/dist/index.js:1243:29)
at async Object.sendRequest (file:///C:/Users/<user>/AppData/Local/deno/npm/registry.npmjs.org/@azure/core-rest-pipeline/1.10.1/dist/index.js:2198:43)
In node version everything is fine. So I think Deno is doing something in a different way.
I check this file @azure/identity/3.1.3/dist/index.js:2489:31 and the code looks like this:
return new Promise((resolve, reject) => {
try {
child_process__default["default"].execFile("az", [
"account",
"get-access-token",
"--output",
"json",
"--resource",
resource,
...tenantSection,
], { cwd: cliCredentialInternals.getSafeWorkingDir(), shell: true }, (error, stdout, stderr) => {
resolve({ stdout: stdout, stderr: stderr, error });
});
}
catch (err) {
reject(err);
}
});
So Deno somehow doesn't see az command from azure-cli...
I'm working on Windows 10. Deno 1.29.4
This is the link to the code on Github. I think the error is quite similar to the one I encountered in https://github.com/denoland/deno/issues/16714.
Thx for github code. Yes, I think it looks similar.
[Edit] Checked on WSL and it is working fine. So it is Windows issue.
So this problem appears to happen with child_process.execFile
and also child_process.exec
, possibly when it is used together with promisify
from util
. The repro below is taken from the aws-cdk
package but also causes this kind of error:
import { exec as _exec } from 'node:child_process';
import { promisify } from 'node:util';
const exec = promisify(_exec);
const { stdout, stderr } = await exec('npm view aws-cdk version');
deno run -A .\asdf.mjs
error: Uncaught Error: Command failed: npm view aws-cdk version
'\"npm view aws-cdk version\"' is not recognized as an internal or external command,
operable program or batch file.
ex = new ExecFileError(
^
at ChildProcess.exithandler (https://deno.land/[email protected]/node/child_process.ts:520:12)
at ChildProcess.emit (https://deno.land/[email protected]/node/_events.mjs:379:28)
at https://deno.land/[email protected]/node/internal/child_process.ts:232:16
at Object.runMicrotasks (deno:core/01_core.js:386:30)
at processTicksAndRejections (https://deno.land/[email protected]/node/_next_tick.ts:62:10)
Okay it's not due to promisify:
import { exec } from 'node:child_process';
const { stdout, stderr } = exec('npm view aws-cdk version');
stderr.on("data", (chunk) => {
console.log(chunk);
});
deno run -A .\asdf.mjs
'\"npm view aws-cdk version\"' is not recognized as an internal or external command,
operable program or batch file.
@js-writer This error has most likely been fixed in https://github.com/denoland/deno_std/pull/3167, it should be available once deno
updates to the latest std
and releases a new version.
If you would like to try it out, you can pull in a local copy of https://github.com/denoland/deno_std, and set an environment variable for deno
:
$env:DENO_NODE_COMPAT_URL='file:///path/to/your/std/'
deno run -A your_script.js