javascript - '。' 在 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 案例。
解决方案
在@derpirscher 的帮助下解决。
const path = require("path");
const prismaBinary = "./node_modules/.bin/prisma";
await exec(
`${path.resolve(prismaBinary)} migrate up --create-db --experimental`
);
推荐阅读
- excel - 按钮消失,代码不再起作用
- c# - 如何在 C# 中访问 Android.os.Build.MODEL
- oracle - 如何从Oracle中2个单词之间的字符串中提取文本
- ios - UIPageControl 用 UICollectionView 页面设置 numberOfPages?
- ruby-on-rails - Rails 对数组和哈希的迭代
- javascript - Javascript JSON stringify 清空我的数组
- c++ - 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- c# - asp mvc中的自动完成脚本
- html - 如何使用 flexbox 将三个相邻的 p 元素均匀排列
- html - 在 SVG 中的蒙版上放置轮廓