Deno: {WSL 2} Permission denied (os error 13)

Created on 1 Nov 2019  ·  14Comments  ·  Source: denoland/deno

OS: WSL 2 (Ubuntu 18.04)
deno: 0.22 (PATH is correct)

$ deno https://deno.land/welcome.ts
Permission denied (os error 13)
$ deno -A https://deno.land/welcome.ts
Permission denied (os error 13)
$sudo deno -A https://deno.land/welcome.ts
sudo: deno: command not found

Most helpful comment

This is not limited to Windows running WSL. I'm on Ubuntu 20.04 and I'm getting the same error. Deno does not install itself globally, only to the current user's folder. Running as sudo does not work as deno is not a known command.

import { serveTLS } from 'https://deno.land/[email protected]/http/server.ts';

const hostname: string = '127.0.0.1';
const port: number = 8000;
const certFile: string = '../../../.ssh/localhost.crt';
const keyFile: string = '../../../.ssh/localhost.key';

const s = serveTLS({ hostname, port, certFile, keyFile });
console.log(`Server running at https://${hostname}:${port}`);

for await (const req of s) {
    req.respond({ body: 'Hello World \n' });
}

deno run --allow-net --allow-read ./index.ts

error: Uncaught PermissionDenied: Permission denied (os error 13)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.listenTls ($deno$/ops/tls.ts:67:10)
    at listenTls ($deno$/tls.ts:51:22)
    at serveTLS (server.ts:313:20)
    at index.ts:8:11

All 14 comments

@chenjianxin Can you provide the output of the following command?

deno -Ldebug https://deno.land/std/examples/welcome.ts

The path changed to https://deno.land/std/examples/welcome.ts ... but it would be better if the error message was
"404 Not Found https://deno.land/welcome.ts"

Except that actually it's not 404 even

> curl -i https://deno.land/welcome.ts
HTTP/2 200
date: Fri, 01 Nov 2019 02:06:22 GMT
content-type: text/html; charset=UTF-8
set-cookie: __cfduid=d3babd2e98b2c22b953b94193d4efbdad1572573982; expires=Sat, 31-Oct-20 02:06:22 GMT; path=/; domain=.deno.land; HttpOnly
cf-cache-status: DYNAMIC
cache-control: public, max-age=0, must-revalidate
cf-ray: 52ea4f1b7d7be724-EWR
age: 6
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
strict-transport-security: max-age=31536000
vary: Accept-Encoding
x-nf-request-id: 9124f991-c4e3-4815-aa14-fbe8d1232a70-529740
server: cloudflare

<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Deno is a secure JavaScript and TypeScript r

@chenjianxin Can you provide the output of the following command?

deno -Ldebug https://deno.land/std/examples/welcome.ts

DEBUG RS - deno_cli::startup_data:26 - Deno isolate init with snapshots.
DEBUG RS - deno::shared_queue:57 - rust:shared_queue:reset
DEBUG RS - deno_cli::ops::dispatch_json:34 - JSON response pre-align, len=323
DEBUG JS - cwd /home/elecbuggy
DEBUG JS - args [ "https://deno.land/std/examples/welcome.ts" ]
DEBUG RS - deno_cli:359 - main_module https://deno.land/std/examples/welcome.ts
DEBUG RS - deno_cli::file_fetcher:124 - fetch_source_file. specifier https://deno.land/std/examples/welcome.ts

Maybe it's the cache directory? What happens if you download to welcome.js and run it as a local JS module?

If I set the permission of deno_dir 700 (owned by root user), then I see the same error.

$ sudo mkdir tmp_deno_dir
$ sudo chmod 700 tmp_deno_dir
$ DENO_DIR=./tmp_deno_dir deno https://deno.land/std/examples/welcome.ts
Permission denied (os error 13)

(Setting the permission to 755 causes a little different error.)

@chenjianxin Can you try to change the permission of deno_dir? (You can find the path of deno_dir by the command deno info)

I think we can panic at wrong permission of deno_dir, but in that case we should show more meaningful error message.

@kt3k I agree

If I set the permission of deno_dir 700 (owned by root user), then I see the same error.

$ sudo mkdir tmp_deno_dir
$ sudo chmod 700 tmp_deno_dir
$ DENO_DIR=./tmp_deno_dir deno https://deno.land/std/examples/welcome.ts
Permission denied (os error 13)

(Setting the permission to 755 causes a little different error.)

@chenjianxin Can you try to change the permission of deno_dir? (You can find the path of deno_dir by the command deno info)

elecbuggy@DESKTOP-F5H2JQL:~$ sudo mkdir /home/elecbuggy/.cache/deno
elecbuggy@DESKTOP-F5H2JQL:~$ sudo chmod 777 /home/elecbuggy/.cache/deno
elecbuggy@DESKTOP-F5H2JQL:~$ deno https://deno.land/std/examples/welcome.ts
Permission denied (os error 13)

BUT

elecbuggy@DESKTOP-F5H2JQL:~$ mkdir tmp_dir
elecbuggy@DESKTOP-F5H2JQL:~$ chmod 777 tmp_dir/
elecbuggy@DESKTOP-F5H2JQL:~$ DENO_DIR=./tmp_dir/ deno https://deno.land/std/examples/welcome.ts
Download https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕


@chenjianxin Try:

$ sudo chmod -R 777 /home/elecbuggy/.cache/deno

@chenjianxin Try:

$ sudo chmod -R 777 /home/elecbuggy/.cache/deno
elecbuggy@DESKTOP-F5H2JQL:~$ sudo chmod -R 777 /home/elecbuggy/.cache/deno
[sudo] password for elecbuggy:
elecbuggy@DESKTOP-F5H2JQL:~$ deno https://deno.land/std/examples/welcome.ts
Permission denied (os error 13)

Same error running this basic code:

import { serveTLS } from "https://deno.land/std/http/server.ts";

const tlsOptions = {
  hostname: "localhost",
  port: 443,
  certFile: "./src/certs/server.pem", // TODO: ENV VAR
  keyFile: "./src/keys/server.pem" // TODO: ENV VAR
};

async function httpsServer() {
  console.log(`Simple HTTPS server listening on ${tlsOptions.hostname}:${tlsOptions.port}`);

  const body = new TextEncoder().encode("Hello HTTPS");
  for await (const req of serveTLS(tlsOptions)) {
      req.respond({ body });
    }
}

httpsServer();

deno --allow-net --allow-read src/index.ts returns this error:

Simple HTTPS server listening on localhost:443
error: Uncaught PermissionDenied: Permission denied (os error 13)
► $deno$/ops/dispatch_json.ts:43:11
    at PermissionDenied ($deno$/errors.ts:81:5)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at listenTLS ($deno$/ops/tls.ts:67:10)
    at listenTLS ($deno$/tls.ts:51:22)
    at serveTLS (server.ts:313:20)
    at httpsServer (index.ts:14:27)
    at index.ts:19:1

Windows 10 on WSL with Ubuntu and Deno 0.40.

This is not limited to Windows running WSL. I'm on Ubuntu 20.04 and I'm getting the same error. Deno does not install itself globally, only to the current user's folder. Running as sudo does not work as deno is not a known command.

import { serveTLS } from 'https://deno.land/[email protected]/http/server.ts';

const hostname: string = '127.0.0.1';
const port: number = 8000;
const certFile: string = '../../../.ssh/localhost.crt';
const keyFile: string = '../../../.ssh/localhost.key';

const s = serveTLS({ hostname, port, certFile, keyFile });
console.log(`Server running at https://${hostname}:${port}`);

for await (const req of s) {
    req.respond({ body: 'Hello World \n' });
}

deno run --allow-net --allow-read ./index.ts

error: Uncaught PermissionDenied: Permission denied (os error 13)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.listenTls ($deno$/ops/tls.ts:67:10)
    at listenTls ($deno$/tls.ts:51:22)
    at serveTLS (server.ts:313:20)
    at index.ts:8:11

I'm getting this error trying to run deno with alosaur module.

OS: Windows 10
WSL: Ubuntu 18.04 (WSL 2)
deno: 1.0.0

app.ts

import { App } from 'https://deno.land/x/alosaur/src/mod.ts';

import * as Areas from './areas/index.ts';

const settings = {
  areas: [Areas.Home, Areas.Book]
}

const app = new App(settings)

app.listen()

run.sh

deno run --allow-run --allow-net --config ./tsconfig.app.json app.ts

tsconfig.app.json

{
  "compilerOptions": {
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true
  }
}

Output after running run.sh

joao-lucas in dev/deno/deno-alosaur-web cxx]===❯ ./run.sh
register Controller:  HomeController
register route:  /
register Controller:  BookController
register route:  /book
error: Uncaught PermissionDenied: Permission denied (os error 13)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.listen ($deno$/ops/net.ts:51:10)
    at listen ($deno$/net.ts:152:22)
    at serve (https://deno.land/[email protected]/http/server.ts:261:20)
    at App.listen (https://deno.land/x/alosaur/src/mod.ts:153:28)
    at file:///home/joao-lucas/dev/deno/deno-alosaur-web/app.ts:11:5

I'm going to close this issue because the original one is quite old - I don't think it is relevant anymore.

@jlcarruda Please try again on v1.0.2 (which will be released momentarily) and start a new issue if the problem persists.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kitsonk picture kitsonk  ·  3Comments

JosephAkayesi picture JosephAkayesi  ·  3Comments

motss picture motss  ·  3Comments

ry picture ry  ·  3Comments

ry picture ry  ·  3Comments