Home > Back-end >  Prisma data proxy npm script errors with 'DATABASE_URL' is not recognized as an internal o
Prisma data proxy npm script errors with 'DATABASE_URL' is not recognized as an internal o

Time:01-13

After creating a Prisma data proxy by following this guide, I switched the DATABASE_URL to my proxy connection string in my .env

DATABASE_URL="prisma://..."

I would like to migrate changes to my database. However, after reading this from Prisma on how to migrate changes with their proxy, I refactored my .env vars to include another variable that will be used in an NPM script whenever I wish to migrate some changes (the script essentially swaps the proxy string with the cloud-hosted DB string)

Refactored .env

DATABASE_URL="prisma://..."

MIGRATE_DATABASE_URL="mysql://..."

Npm script inside package.json

{
  ...,
  "scripts": {
    "generate-client": "prisma generate --data-proxy",
    "migrate-deploy": "DATABASE_URL=\"$MIGRATE_DATABASE_URL\" prisma migrate deploy",
    "dev": "DATABASE_URL=\"$MIGRATE_DATABASE_URL\" prisma migrate dev",
  }
}

The Problem: whenever I run npm run migrate-deploy, I recieve this error: 'DATABASE_URL' is not recognized as an internal or external command, operable program or batch file.

CodePudding user response:

The error message you're seeing suggests that the system is unable to recognize the DATABASE_URL environment variable you're trying to set in the migrate-deploy script. One possible reason for this is that the script is being run in a shell that doesn't support setting environment variables in this way. One solution to this issue would be to prefix the command in the script with cross-env, it will allow you to set environment variables in a cross-platform way. Make sure you have installed cross-env package in your application npm install cross-env

  • Related