WSL环境下执行web-ext run启动Firefox扩展失败求助
问题:WSL中运行
web-ext run无法找到Firefox的解决方案 问题场景
我正在开发一个简单的Firefox扩展,在Windows 10的Ubuntu Linux子系统(WSL)中执行web-ext run命令时出现找不到Firefox的错误,手动指定Windows路径后问题依然存在。
初始错误信息
执行web-ext run时的报错:
Error: not found: firefox at F (/usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/which/which.js:63:19) at E (/usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/which/which.js:72:29) at /usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/which/which.js:81:16 at /usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/isexe/index.js:44:5 at /usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/isexe/access.js:8:5 at FSReqCallback.oncomplete (node:fs:198:23)
环境说明
- 运行环境:Windows 10的Ubuntu Linux子系统(WSL)
- 已尝试Firefox开发者版,问题一致
尝试过的命令及响应
尝试执行以下命令:
web-ext run -v web-ext run -v --firefox="C:\Program Files\Mozilla Firefox\firefox.exe"
得到的响应:
[/usr/local/lib/node_modules/web-ext/lib/program.js][info] Version: 7.6.2 [/usr/local/lib/node_modules/web-ext/lib/program.js][debug] Discovering config files. Set --no-config-discovery to disable [/usr/local/lib/node_modules/web-ext/lib/config.js][debug] Discovered config "/home/knuffle98/.web-ext-config.js" does not exist or is not readable [/usr/local/lib/node_modules/web-ext/lib/config.js][debug] Discovered config "/mnt/c/Users/Knuffle98/Code/Repos/Applicator/package.json" does not exist or is not readable [/usr/local/lib/node_modules/web-ext/lib/config.js][debug] Discovered config "/mnt/c/Users/Knuffle98/Code/Repos/Applicator/web-ext-config.js" does not exist or is not readable [/usr/local/lib/node_modules/web-ext/lib/cmd/run.js][info] Running web extension from /mnt/c/Users/Knuffle98/Code/Repos/Applicator [/usr/local/lib/node_modules/web-ext/lib/util/manifest.js][debug] Validating manifest at /mnt/c/Users/Knuffle98/Code/Repos/Applicator/manifest.json [/usr/local/lib/node_modules/web-ext/lib/extension-runners/firefox-desktop.js][debug] Creating new Firefox profile [/usr/local/lib/node_modules/web-ext/lib/firefox/index.js][debug] Running Firefox with profile at /tmp/firefox-profilesTWUXQ/ [/usr/local/lib/node_modules/web-ext/lib/program.js][error] Error: not found: C:\Program Files\Mozilla Firefox\firefox.exe at F (/usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/which/which.js:63:19) at E (/usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/which/which.js:72:29) at /usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/which/which.js:81:16 at /usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/isexe/index.js:44:5 at /usr/local/lib/node_modules/web-ext/node_modules/fx-runner/node_modules/isexe/access.js:8:5 at FSReqCallback.oncomplete (node:fs:198:23)
问题核心
请问问题出在哪里?
解决方案
问题根源是WSL不支持直接识别Windows风格的盘符路径,你用C:\Program Files\...这种格式在WSL中执行,系统无法定位到对应文件。
解决方法分两种:
方法1:使用WSL的Windows路径映射格式
把Windows路径转换成WSL能识别的格式——Windows的C:盘对应WSL的/mnt/c/,路径分隔符从\改成/。比如原路径C:\Program Files\Mozilla Firefox\firefox.exe要写成/mnt/c/Program Files/Mozilla Firefox/firefox.exe,执行命令:
web-ext run -v --firefox="/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
方法2:在WSL中安装Firefox
直接在Ubuntu子系统里安装Firefox,这样web-ext就能自动找到可执行文件,无需手动指定路径:
sudo apt update sudo apt install firefox
安装完成后直接执行web-ext run即可。
额外提示
如果使用Firefox开发者版,同样要转换路径格式,默认路径对应WSL格式为/mnt/c/Program Files/Firefox Developer Edition/firefox.exe,执行命令:
web-ext run -v --firefox="/mnt/c/Program Files/Firefox Developer Edition/firefox.exe"
内容的提问来源于stack exchange,提问作者Knuffle98
相关产品推荐
相关产品推荐

