首页 > 解决方案 > '。' 在 exec() 中使用时不被识别为内部或外部命令,但从命令行运行时不被识别

问题描述

以下是使用 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 案例。

标签: javascriptnode.jswindowsnpmprisma

解决方案


在@derpirscher 的帮助下解决。

const path = require("path");
const prismaBinary = "./node_modules/.bin/prisma";
await exec(
  `${path.resolve(prismaBinary)} migrate up --create-db --experimental`
);

推荐阅读