I have created simple app using typescript prisma client
When executing simple query to receive users list in graphql playground, result contains errros array with
error "only absolute urls are supported". It occurs in node-fetch, but i analyzed trace and found that some package call fetch with url = undefined.
Then I add console.log to generated prisma-client/index.js:
console.log(`${process.env["PRISMA_ENDPOINT"]}`);
exports.Prisma = prisma_lib_1.makePrismaClientClass({
typeDefs,
models,
endpoint: `${process.env["PRISMA_ENDPOINT"]}`
});
And when code starts value of process.env["PRISMA_ENDPOINT"] is undefined
I used command: nodemon --exec ts-node src/index.js
and in src/index.js code starts with:
import dotenv from "dotenv";
dotenv.config();
import createServer from "./createServer";
and in createServer:
import { prisma } from "./generated/prisma-client";
So if I use regular require instead of ES6 imports and run code without ts-node or babel-node no error occurs and process.env["PRISMA_ENDPOINT"] is always has value
Can anybody explain why it is happening?
As I understand this happenning because when ts compiles code it runs without env loaded using dotenv and then runs compiled code which already set endpoint to undefined
What is correct way to fix it?
Versions (please complete the following information):
Windows 10for some reason can't reproduce it again
UP! Same error.
A complete restart solved this issue for me, for some reason.
I found the cause.
In prisma.yml, I have the field, endpoint, set to ${env:PRISMA_ENDPOINT}. Make sure whichever environment runs the Node.js project has the PRISMA_ENDPOINT environment variable set by using either of these methods:
dotenv like npm library in your Node.js projectI had this issue as well and found that using
import dotenv from "dotenv";
dotenv.config();
does not work for the whole project but just for that file. Try adding that same code to your prisma-client/index.js (and/or any other file(s) you need variables from your .env file).
Hi @RevNelson
This is a limitation of ES modules.
If you can import it like this:
require('dotenv').config();
Then it will be available in all other files.
See: https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
I had the same issue recently and even adding
require('dotenv').config();
in the entry index.js didn't load env variables in files other than index.js.
I was using Backpack as a build tool so I added dotenv-webpack to fix it.
Most helpful comment
UP! Same error.