TypeError: Deno.readFileSync is not a function
borisdiakur opened this issue · comments
Getting this on deno deploy when loading config:
TypeError: Deno.readFileSync is not a function
at parseFile (https://deno.land/x/dotenv@v3.2.0/mod.ts:103:59)
at config (https://deno.land/x/dotenv@v3.2.0/mod.ts:42:18)
No issues when running locally.
The cause of this issue might be that
only stable APIs of Deno are made available in Deploy.
and Deno.readFileSync
is not (yet) part of the stable API.
See https://deno.com/deploy/docs/runtime-api#deno-apis
This should be fixable by replacing Deno.readFileSync
with await Deno.readFile
and making the consuming method async.
Just realised that I can use https://deno.land/std/dotenv 😅
Sorry for reopening this ticket, but I run in the same error during deployment using Deno deploy:
This is my mongo.ts
:
import {MongoClient} from "./deps.ts";
import {config} from "./deps.ts";
const env = await config()
console.log("ENV", env);
const client = new MongoClient();
await client.connect("mongodb://" + env.MONGO_USER + ":" + env.MONGO_PW + "@" + env.MONGO_HOST + ":" + env.MONGO_PORT + "/?authSource=admin&readPreference=primary&ssl=false&directConnection=true");
const db = client.database("deno");
export {db};
And my deps.ts
:
export {
MongoClient,
ObjectId
} from "https://deno.land/x/mongo@v0.31.1/mod.ts";
export {
Router,
Status
} from "https://deno.land/x/oak/mod.ts";
export {
config
} from "https://deno.land/x/dotenv/mod.ts";
Sorry for reopening this ticket, but I run in the same error during deployment using Deno deploy:
This is my
mongo.ts
:import {MongoClient} from "./deps.ts"; import {config} from "./deps.ts"; const env = await config() console.log("ENV", env); const client = new MongoClient(); await client.connect("mongodb://" + env.MONGO_USER + ":" + env.MONGO_PW + "@" + env.MONGO_HOST + ":" + env.MONGO_PORT + "/?authSource=admin&readPreference=primary&ssl=false&directConnection=true"); const db = client.database("deno"); export {db};
And my
deps.ts
:export { MongoClient, ObjectId } from "https://deno.land/x/mongo@v0.31.1/mod.ts"; export { Router, Status } from "https://deno.land/x/oak/mod.ts"; export { config } from "https://deno.land/x/dotenv/mod.ts";
You are importing the synchronous function, try using the asynchronous one.
import { configAsync } from "https://deno.land/x/dotenv/mod.ts";
instead of
import { config } from "https://deno.land/x/dotenv/mod.ts";