Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

安装依赖报错 #161

Closed
dream-wk opened this issue Mar 26, 2024 · 10 comments
Closed

安装依赖报错 #161

dream-wk opened this issue Mar 26, 2024 · 10 comments

Comments

@dream-wk
Copy link

Bug report(问题描述)

Progress: resolved 1430, reused 1427, downloaded 0, added 2, done
node_modules/.pnpm/nx@18.1.2/node_modules/nx: Running postinstall script, failed in 551ms
.../.pnpm/nx@18.1.2/node_modules/nx postinstall$ node ./bin/post-install
│ E:\tem\vue3-antdv-admin-main\node_modules.pnpm\nx@18.1.2\node_modules\nx\src\native\index.js:244
│ throw loadError
│ ^
│ Error: The specified module could not be found.
│ \?\E:\tem\vue3-antdv-admin-main\node_modules.pnpm@nx+nx-win32-x64-msvc@18.1.2\node_modules@nx\nx-win32-x64-msvc\nx.win32-x64-msvc.node
│ at Module._extensions..node (node:internal/modules/cjs/loader:1452:18)

Steps to reproduce(问题复现步骤)

Screenshot or Gif(截图或动态图)

Link to minimal reproduction(最小可在线还原 demo)

Other relevant information(格外信息)

  • Your OS:
  • Node.js version:
  • packageManager:
@buqiyuan
Copy link
Owner

buqiyuan commented Mar 26, 2024

没复现,要不你将 package.json 中的这行:

"postinstall": "node ./scripts/postinstall.js || pnpm nx:build",

改为:

"postinstall": "pnpm build:pkg",

@dream-wk
Copy link
Author

图片
还是不行

@dream-wk
Copy link
Author

有没有可能是我的版本问题呢
node是18.19.1
pnpm 8.15.5

@buqiyuan
Copy link
Owner

版本看起来没问题,按理说你将 postinstall 脚本改为 pnpm build:pkg 之后,就没有执行 nx 相关的命令或脚本了呀🤔

@dream-wk
Copy link
Author

图片
依赖删了 重新装 还是报错

@buqiyuan
Copy link
Owner

哦,原理 nx 自己还有个 postinstall 的脚本
image
这样吧!你 pnpm remove nx 卸载掉 nx 这个包。
我 mac 复现不了你的问题,估计可能是电脑环境问题吧!

@buqiyuan
Copy link
Owner

刚在 nx 官方文档 看了下,可能是这条没满足吧!没关系,你卸载掉 nx 也不影响什么,它只是用来提高 monorepo 构建效率的
image

@dream-wk
Copy link
Author

图片

@buqiyuan
Copy link
Owner

buqiyuan commented Mar 26, 2024

插件本身没问题,你可以手动 pnpm build:pkg 构建好相关插件,然后再 pnpm install 应该就可以了。
因为我在 package.json 有如下的配置,pnpm 没有正常同步这两个依赖项,事实上这应该算是 pnpm 官方的 bug,详见此 issue

"dependenciesMeta": {
"@admin-pkg/vite-plugin-msw": {
"injected": true
},
"@admin-pkg/vite-plugin-tinymce-resource": {
"injected": true
}

稍后,我将针对你这个情况做一个降级的处理,项目中 scripts/postinstall.js 这个脚本本身也是为了暂时兼容这个 bug 的
import { promisify } from 'node:util';
import { exec } from 'node:child_process';
// TODO 此脚本用于临时解决:https://github.com/pnpm/pnpm/issues/6088
const execAsync = promisify(exec);
const executeCommand = async (cmd) => {
try {
const { stdout, stderr } = await execAsync(cmd);
console.log('标准输出:', stdout);
stderr && console.error('标准错误:', stderr);
} catch (error) {
console.error('执行命令时出错:', error);
}
};
if (process.env.POSTINSTALL_EXECUTED === 'true') {
// console.log('执行过了');
} else {
// console.log('首次执行');
process.env.POSTINSTALL_EXECUTED = 'true';
await executeCommand('pnpm nx:build');
await executeCommand('pnpm install');
}

@dream-wk
Copy link
Author

手动 pnpm build:pkg 构建好相关插件,然后再 pnpm install 应该就可以了

还是不行的 一样的报错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants