0

Unable to import the stdlib files from deno.land to local cache on running mod.ts.

error: error sending request for url (https://deno.land/std/encoding/csv.ts): error trying to connect: tcp connect error: An attempt was made to access a socket in a way forbidden by its access permissions. (os error 10013) Imported from "file:///C:/Current_Tasks/Deno/Kepler/mod.ts:3"

Is there anything additional that needs to be enabled to import these files?

import { join } from "https://deno.land/std/path/mod.ts";
import { BufReader } from "https://deno.land/std/io/bufio.ts";
import { parse } from "https://deno.land/std/encoding/csv.ts";

async function loadPlanetsData() {
  const path = join(".", "test.csv");
  const file = await Deno.open(path);

  const bufReader = new BufReader(file);

  const result = await parse(bufReader, {
    header: true,
    comment: "#",
  });

  Deno.close(file.rid);

  console.log(result);
}

await loadPlanetsData();

Update: Used deno run --allow-read mod.ts

anbu25
  • 1
  • 2

1 Answers1

0
import { join } from "https://deno.land/std/path/mod.ts";
import { BufReader } from "https://deno.land/std/io/bufio.ts";
import { parse } from "https://deno.land/std/encoding/csv.ts";

async function loadPlanetsData() {
    const path = join(".", "test.csv");
    const file = await Deno.open(path);

    const bufReader = new BufReader(file);

    const result = await parse(bufReader, {
        header: true,
        comment: "#",
    });

    Deno.close(file.rid);

    console.log(result);
}

await loadPlanetsData();

While running this file you need to give read access to the Deno.

Deno is secure by default. Therefore, unless you specifically enable it, a deno module has no file, network, or environment access for example. Access to security sensitive areas or functions requires the use of permissions to be granted to a deno process on the command line.

For the following example, mod.ts has been granted read-only access to the file system. It cannot write to it, or perform any other security sensitive functions.

deno run --allow-read mod.ts

Nikhil Savaliya
  • 2,138
  • 4
  • 24
  • 45
  • Nikhil, thanks for taking time. Yes i did use the following permissions while running the commands. And it returns the error above mentioned error – anbu25 Jul 07 '20 at 04:54
  • is there issue with internet connection/firewall ? – Nikhil Savaliya Jul 07 '20 at 08:03
  • Seems like you have to use the --allow-net permission. Please read the permissions list https://deno.land/manual/getting_started/permissions – Santi Jul 07 '20 at 14:38