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

Viewed 2289

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.

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`
);
Related