⨯ cannot execute cause=fork/exec...pnpm\bin\pnpm.cjs: %1 is not a valid Win32 application.

简介: ⨯ cannot execute cause=fork/exec...pnpm\bin\pnpm.cjs: %1 is not a valid Win32 application.

记录一个错误,其抛出信息如下:

> electron-builder
  • electron-builder  version=23.6.0 os=10.0.22621
  • loaded configuration  file=package.json ("build" field)
  • electron-rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies
To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`
  • writing effective config  file=release\builder-effective-config.yaml
  • "electron-squirrel-startup" dependency is not required for NSIS
  • rebuilding native dependencies  dependencies=sqlite3@5.1.6 platform=win32 arch=x64
  ⨯ cannot execute  cause=fork/exec C:\Users\jcstudio.tech\AppData\Roaming\npm\node_modules\pnpm\bin\pnpm.cjs: %1 is not a valid Win32 application.
                    command='C:\Users\jcstudio.tech\AppData\Roaming\npm\node_modules\pnpm\bin\pnpm.cjs' rebuild sqlite3@5.1.6
                    workingDir=
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

这是一个由 pnpm 导致的问题,起初没有使用含有 sqllite3 的模块,构建是没有问题的,使用了 sqllite3 之后,在 electron-builder 进行构建时显示 xxx\pnpm.cjs 不是一个合法的 Win32 应用。

pnpm.cjs 文件上方有一个 shebang (#!开头 ):

#!/usr/bin/env node

最初在类unix操作系统中一个文本文件带有 #! 开头,就会当做一个执行文件来运行。而 /usr/bin/env node 其实表示的是通常情况下在 Linux 系统中安装的 nodeJS 二进制文件目录,相当于 Windows上的 Node.exe 的绝对路径。放在windows上面时,这个路径就会产生错误。

修复方式:

如果你的 node.exe 添加到了 path 环境变量中,可以直接将路径改成 node。如果没明白请往下看详细步骤。

详细步骤:

找到pnpm.cjs文件,比如我这里的是:

C:\Users\jcstudio.tech\AppData\Roaming\npm\node_modules\pnpm\bin\pnpm.cjs

打开该文件:

#!/usr/bin/env node
const [major, minor] = process.version.slice(1).split('.')
const COMPATIBILITY_PAGE = `Visit https://r.pnpm.io/comp to see the list of past pnpm versions with respective Node.js version support.`
// We don't use the semver library here because:
//  1. it is already bundled to dist/pnpm.cjs, so we would load it twice
//  2. we want this file to support potentially older Node.js versions than what semver supports
if (major < 14 || major == 14 && minor < 6) {
  console.log(`ERROR: This version of pnpm requires at least Node.js v14.6
The current version of Node.js is ${process.version}
${COMPATIBILITY_PAGE}`)
  process.exit(1)
}
global['pnpm__startedAt'] = Date.now()
require('../dist/pnpm.cjs')
// if you want to debug at your local env, you can use this
// require('../lib/pnpm')

将第一行替换为:

#!node

如果没能解决,试试参考以下页面有相关问题:

https://github.com/v9u/sqlite_test

https://github.com/electron-userland/electron-builder/issues/6933#issuecomment-1213438889

目录
相关文章
|
开发者
UOS系统如何给软件签名
UOS系统如何给软件签名
UOS系统如何给软件签名
|
缓存 资源调度 区块链
Electron打包图标不显示解决方案
Electron打包图标不显示解决方案
3429 0
|
Shell 网络安全 开发工具
手把手教你配置Git客户端上传代码至Gitlab仓库
手把手教你配置Git客户端上传代码至Gitlab仓库
1067 1
手把手教你配置Git客户端上传代码至Gitlab仓库
|
27天前
|
人工智能 自然语言处理 机器人
AI大模型时代选型参考:国内常用的智能客服系统推荐
2026年智能客服选型重心已从“能否答对”转向“能否办成”。IDC数据显示,2025年中国企业级市场规模达71.9亿元,同比增长55.3%;Gartner预测2026年底40%企业应用将集成任务型AI Agent。阿里云瓴羊Quick Service以“感知—理解—决策—执行”四层闭环架构,支持对话内查物流、改地址、退款等真实操作,验证了AI从问答到办事的能力跃迁。(239字)
|
7月前
|
前端开发 JavaScript API
前端组件库——Naive UI知识点大全(四)
教程来源 https://tmywi.cn/category/jiaju.html 本文档汇总Naive UI开发中高频问题与最佳实践:涵盖动态表单校验失效、Select复杂对象绑定、表格row-key响应、暗黑模式刷新及离散API调用等解决方案,并提供项目结构、组件封装、表格逻辑复用和组件注册等工程化建议,助力高效构建高质量Vue 3应用。
|
存储 固态存储 算法
固态硬盘损坏后还能做数据恢复吗?完整指南
固态硬盘(SSD)因速度快、抗震动、低噪音被广泛使用,但一旦损坏,用户常因慌乱导致二次损失。本文解析SSD损坏后的数据恢复可行性,介绍逻辑损坏、固件异常、物理损坏三种常见情况,并提供对应的恢复方法与预防措施,帮助用户科学应对数据丢失风险,提升恢复成功率。
NPM——Electron failed to install correctly, please delete node_modules/electron and try
NPM——Electron failed to install correctly, please delete node_modules/electron and try
2227 0
|
人工智能 自然语言处理 Java
Spring AI,Spring团队开发的新组件,Java工程师快来一起体验吧
文章介绍了Spring AI,这是Spring团队开发的新组件,旨在为Java开发者提供易于集成的人工智能API,包括机器学习、自然语言处理和图像识别等功能,并通过实际代码示例展示了如何快速集成和使用这些AI技术。
14287 4
Spring AI,Spring团队开发的新组件,Java工程师快来一起体验吧
|
Unix
深入理解 CMake 的 `cmake --build` 命令
深入理解 CMake 的 `cmake --build` 命令
3725 1
|
Ubuntu Linux
Ubuntu 报错:System has not been booted with systemd as init system (PID 1). Can‘t operate.
系统未使用 `systemd` 初始化导致错误。解决方法是通过 `apt` 安装。首先备份并更换`sources.list`,添加阿里云镜像源,然后更新源并以管理员权限运行 `apt-get install systemd -y` 和 `apt-get install systemctl -y` 安装所需组件。
12817 3

热门文章

最新文章