🐛 [Bug]: Execute pnpm i command error: Error: Expected "0.23.1" but got "0.18.20"
Version
latest
Vue Version
latest
Link to minimal reproduction
- os version: macOS 12.2
- node version: v18.19.0
- npm version: 10.2.3
- pnpm version: v7.22.0
clone 项目代码之后,在 dev 分支根目录执行 pnpm i 命令报错:
node_modules/.pnpm/[email protected]/node_modules/nx: Running postinstall script, done in 375ms
node_modules/.pnpm/[email protected]/node_modules/esbuild: Running postinstall script, failed in 272ms
.../[email protected]/node_modules/esbuild postinstall$ node install.js
│ tiny-vue/node_modules/.pnpm/[email protected]/node_modules/esbuild/install.js:134
│ throw new Error(`Expected ${JSON.stringify(versionFromPackageJSON)} but got ${JSON.stringify(stdout)}`);
│ ^
│ Error: Expected "0.23.1" but got "0.18.20"
Step to reproduce
同上
What is expected
No response
What is actually happening
No response
What is your project name
Demo
Any additional comments (optional)
No response
I encountered a bug related to the installation of esbuild, and I’m sharing my findings here for anyone who may face a similar issue.
TL;DR: Run the following command to resolve the issue:
npm install esbuild@^0.18.0 --save-dev
Explanation: This issue arises due to several factors:
- The first time the installation encounters esbuild as a dependency, it does so without a fixed version. This is often due to a library that requests esbuild without specifying a particular version.
- Because it’s the first time npm sees this dependency, it performs a fetch for the latest version, which in this case is [email protected].
- Another library then requires a specific version of esbuild that does not match the latest version fetched.
- After the installation completes, npm runs the install script, which compares the downloaded package to the required version from the dependencies, resulting in a failure.
- The solution is to prevent the unnecessary fetch by defining a specific version from the start.
I hope this helps others who encounter the same issue!
将 Node.js 升级到 v20.17.0 之后,报了另一个错:
internals/unplugin-virtual-template build$ tsup
│ internals/vue-vite-import build$ rimraf dist && tsup src/index.ts --dts --format cjs,esm
│ internals/unplugin-tiny-vue build$ rimraf dist && tsup src/index.ts --dts --format cjs,esm
│ internals/unplugin-virtual-template build: ✘ [ERROR] Cannot start service: Host version "0.23.1" does not match binary version "0.18.20"
│ internals/unplugin-virtual-template build: 1 error
│ internals/unplugin-virtual-template build: Error: The service was stopped
│ internals/unplugin-virtual-template build: at /tiny-vue/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:968:34
│ internals/unplugin-virtual-template build: at responseCallbacks.<computed> (/tiny-vue/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:62
│ internals/unplugin-virtual-template build: at Socket.afterClose (/tiny-vue/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:613:28)
│ internals/unplugin-virtual-template build: at Socket.emit (node:events:531:35)
│ internals/unplugin-virtual-template build: at endReadableNT (node:internal/streams/readable:1696:12)
│ internals/unplugin-virtual-template build: at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
│ internals/unplugin-virtual-template build: Failed
│ undefined
│ /tiny-vue/internals/unplugin-virtual-template:
│ ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @opentiny-internal/[email protected] build: `tsup`
│ Exit status 1
macOS 12.2 Node.js v20.10.0 npm 10.2.3 pnpm 9.12.2
以上环境下暂无此问题。
Bot detected the issue body's language is not English, translate it automatically.
macOS 12.2 Node.js v20.10.0 npm 10.2.3 pnpm 9.12.2
There is no such problem in the above environment.