在Windows上运行Rust交叉编译的Playwright项目
文章目录
背景
有一个Playwright的项目,使用rust编写后想在Windows上执行,开发机是macOS,就需要先在macOS上进行交叉编译生成Windows可执行文件,然后再将生成的changdu.exe复制到Windows机器上运行。
交叉编译
在macOS上运行下边的命令进行交叉编译:
brew install mingw-w64
cargo build --release --target x86_64-pc-windows-gnu
生成的Windows可执行文件位于:
target/x86_64-pc-windows-gnu/release/your_program.exe
在Windows上运行
将生成的your_program.exe复制到Windows机器上,尝试了下载最新的nodejs,安装后分别运行了
node -v
npm -v
确认环境正常后,直接在命令行运行:
npm init playwright@latest
npm install playwright
npx playwright install
npx playwright --version
都能正常输出结果,安装也正常安装,Playwright版本号也正常返回了,但是运行exe时候总是会提示Error: Playwright server not found. Install with: npm install playwright
解决方案
下载 Windows 版 Playwright driver,解压到 exe 同级目录,设置环境变量:
- 下载: https://playwright.azureedge.net/builds/driver/playwright-1.59.1-win32_x64.zip
- 解压到 exe 旁边的 drivers\ 目录
- 启动时设置环境变量即可正常运行:
set PLAYWRIGHT_DRIVER_PATH=.\drivers\playwright-1.59.1-win32_x64
your_program.exe
文章作者 pengxiaochao
上次更新 2026-05-02
许可协议 不允许任何形式转载。