3

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.

Michael
  • 191
  • 1
  • 10
  • My guess is that `npm run test` is running in a different shell than the command line (probably Windows CMD shell) on which you're trying (and failing) to execute the command directly. That command looks like it's designed to run in bash or similar. – Steve Aug 08 '20 at 13:12
  • You really can run `./node_modules/...` from the CMD commandline? I doubt that. Or do you change into the respective subdirectory. You could use `path.resolve()` to resolve the relative path to your executable into an absolute path. On windows systems, `path.resolve()` can also deal with linux path delimeters `/` and will return a path with windows path delimeters `\ ` – derpirscher Aug 08 '20 at 14:04
  • If you have some bash compatible shell installed (for instance MINGW64 which is installed with git for windows) you could also set your script-shell for npm like shown in this question https://stackoverflow.com/questions/23243353/how-to-set-shell-for-npm-run-scripts-in-windows – derpirscher Aug 08 '20 at 14:07
  • @derpirscher you are correct i had a terminal open within the root of the project. And your solution worked. Thank you. – Michael Aug 08 '20 at 18:28

1 Answers1

3

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`
);
Michael
  • 191
  • 1
  • 10