Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'.' is not recognized as an internal or external command thrown when used in exec(), but not when run from command line

The following is part of a script that is run using npm run test.

async setup() {
    process.env.DATABASE_URL = this.databaseUrl;
    this.global.process.env.DATABASE_URL = this.databaseUrl;
    await exec(`./node_modules/.bin/prisma migrate up --create-db --experimental`);
    return super.setup();}

This throws the following error

Command failed: ./node_modules/.bin/prisma migrate up --create-db --experimental
'.' is not recognized as an internal or external command,
operable program or batch file.

When run from the cmd the command works as expected. What is the correct way to reference the binary file within exec()? I am using windows incase that is relevant.

like image 973
Michael Avatar asked Sep 10 '25 03:09

Michael


1 Answers

Solution with help from @derpirscher.

const path = require("path");
const prismaBinary = "./node_modules/.bin/prisma";
await exec(
  `${path.resolve(prismaBinary)} migrate up --create-db --experimental`
);
like image 137
Michael Avatar answered Sep 12 '25 16:09

Michael