⨯ 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

目录
相关文章
|
资源调度 JavaScript Windows
yarn install命令报错解决办法-warning package-lock.json found.
yarn install命令报错解决办法-warning package-lock.json found.
369 0
|
8月前
|
Linux iOS开发 MacOS
pnpm全局安装报错:Run “pnpm setup“ to create it automatically, or set the global-bin-dir setting, or the PN
pnpm全局安装报错:Run “pnpm setup“ to create it automatically, or set the global-bin-dir setting, or the PN
2271 0
|
8月前
项目打包报错“caniuse-lite is outdated. Please run next command `npm update`”的解决方案
项目打包报错“caniuse-lite is outdated. Please run next command `npm update`”的解决方案
393 1
npm run dev启动报错:Error: Cannot find module 'semver'
npm run dev启动报错:Error: Cannot find module 'semver'
244 0
|
23天前
|
JavaScript 算法 前端开发
为什么npm run serve正常,npm run build就报错:digital envelope routines::unsupported
通过本文的分析,我们详细介绍了 `npm run serve`正常但 `npm run build`时报错:`digital envelope routines::unsupported`的原因及解决方案。主要从检查Node.js版本、更新依赖、检查依赖库、配置文件及环境变量等方面进行了深入探讨。希望本文能帮助开发者解决这一问题,确保项目顺利构建和部署。
54 6
|
5月前
|
缓存 资源调度 JavaScript
Nodejs 命令行调用 exec 与 spawn 差异--- 解决 spawn yarn ENOENT error
Nodejs 命令行调用 exec 与 spawn 差异--- 解决 spawn yarn ENOENT error
|
8月前
|
资源调度 前端开发
npm/yarn link 测试包时报错 Warning: Invalid hook call. Hooks can only be called ...
npm/yarn link 测试包时报错 Warning: Invalid hook call. Hooks can only be called ...
99 0
|
JavaScript
Vue报错:npm run start npm ERR! missing script: start
Vue报错:npm run start npm ERR! missing script: start
|
JavaScript 前端开发 测试技术
npm run dev启动报错:TypeError: Cannot read property 'upgrade' of undefined
npm run dev启动报错:TypeError: Cannot read property 'upgrade' of undefined
260 0
|
JavaScript Shell
typescript vscode /bin/sh: ts-node: command not found
typescript vscode /bin/sh: ts-node: command not found
155 0

热门文章

最新文章