javascript - '.'不被识别为在 exec() 中使用时抛出的内部或外部命令,但从命令行运行时则不会

标签 javascript node.js windows npm prisma

以下是使用 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/

相关文章:

javascript - 日期选择器上的 selectValue 不起作用

javascript - isAuthenticated() 函数无法正常工作 Node.js Passport

Windows 调试符号 <unnamed-tag>

c++ - Win32_NetworkAdapter 类为 boolean NetEnabled 返回 NULL;

javascript - 从 Express 路由引发异常时,未调用未处理的异常事件处理程序

javascript - onMouseOver JavaScript 与 CSS list-style-image

javascript - 如何在jsp中显示下拉框的值

database - 为需要处理大量 I/O 的 Node.js 服务器选择数据库?

javascript - 当数组超过一定大小限制时,node.js 会大幅减速

c# - 如果多个应用程序实例正在运行,如何获取应用程序的事件/前台实例?