以下是使用 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();}
这会引发以下错误
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.
当从 cmd 运行时,该命令按预期工作。在 exec() 中引用二进制文件的正确方法是什么?我正在使用相关的 Windows incase。
最佳答案
在@derpirscher 的帮助下解决。
const path = require("path");
const prismaBinary = "./node_modules/.bin/prisma";
await exec(
`${path.resolve(prismaBinary)} migrate up --create-db --experimental`
);
关于javascript - '.'不被识别为在 exec() 中使用时抛出的内部或外部命令,但从命令行运行时则不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63315725/