Prisma1: Error: only absolute urls are supported

Created on 26 Nov 2018  路  7Comments  路  Source: prisma/prisma1

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):

  • OS: Windows 10
  • node: 8.11.3
  • "graphql": "^0.13.2",
  • "graphql-yoga": "^1.16.7",
  • "prisma": "^1.21.0",
  • "prisma-client-lib": "^1.21.0"

Most helpful comment

UP! Same error.

All 7 comments

for 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:

  1. Use OS environment variables settings
  2. Use dotenv like npm library in your Node.js project

I 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlessandroAnnini picture AlessandroAnnini  路  3Comments

ragnorc picture ragnorc  路  3Comments

schickling picture schickling  路  3Comments

jannone picture jannone  路  3Comments

marktani picture marktani  路  3Comments