denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3.06k stars 608 forks source link

node: Error when running `deno run -A npm:firebase-tools` #2995

Closed ayame113 closed 1 year ago

ayame113 commented 1 year ago

I get an error when running firebase cli (npm:firebase-tools) on Windows.

> deno --version
deno 1.28.3 (release, x86_64-pc-windows-msvc)
v8 10.9.194.5
typescript 4.8.3
> deno run -A npm:firebase-tools --version
error: Uncaught NotSupported: The operation is not supported
  Deno.chmodSync(pathModule.toNamespacedPath(path), mode);
       ^
    at Object.chmodSync (deno:runtime/js/30_fs.js:22:9)
    at Object.chmodSync (https://deno.land/std@0.167.0/node/_fs/_fs_chmod.ts:32:8)
    at Function.writeFileSync [as sync] (file:///C:/Users/ayame/AppData/Local/deno/npm/registry.npmjs.org/write-file-atomic/3.0.3/index.js:236:12)
    at Configstore.set all (file:///C:/Users/ayame/AppData/Local/deno/npm/registry.npmjs.org/configstore/5.0.1/index.js:61:20)
    at Configstore.set (file:///C:/Users/ayame/AppData/Local/deno/npm/registry.npmjs.org/configstore/5.0.1/index.js:91:12)
    at Object.<anonymous> (file:///C:/Users/ayame/AppData/Local/deno/npm/registry.npmjs.org/firebase-tools/11.17.0/lib/track.js:20:31)
    at Object.<anonymous> (file:///C:/Users/ayame/AppData/Local/deno/npm/registry.npmjs.org/firebase-tools/11.17.0/lib/track.js:153:4)
    at Module._compile (deno:ext/node/02_require.js:734:36)
    at Object.Module._extensions..js (deno:ext/node/02_require.js:767:12)
    at Module.load (deno:ext/node/02_require.js:645:34)

I debugged this error and found it was caused by fs.chmodSync() incompatibility on windows. The code below gives an error only on deno.

// import fs from "node:fs";
import fs from "https://deno.land/std@0.167.0/node/fs.ts";
fs.chmodSync("tmp.txt", 0o0600);
> deno run ./tmp.mjs
error: Uncaught NotSupported: The operation is not supported
    at async Object.chmod (deno:runtime/js/30_fs.js:26:5)

According to https://github.com/denoland/deno/issues/4357#issue-580914687, when you perform an operation that is not available in windows (such as changing read permissions), node does not throw, but deno throws.

ayame113 commented 1 year ago

According to https://github.com/denoland/deno/issues/4357#issue-580914687, when you perform an operation that is not available in windows (such as changing read permissions), node does not throw, but deno throws.

Introducing this behavior into Deno seems to have been a deliberate decision (https://github.com/denoland/deno/pull/4446).

Perhaps the solution is to enclose the Deno.chmod{,Sync} in the _fs_chmod.ts with try-catch?