简体   繁体   English

`yarn add` 和 `npm install --save` 都不会将包安装到本地项目

[英]`yarn add` and `npm install --save` both does not install packages to local project

I forked a React Native-derived framework project which the original author has recently stopped maintaining.我分叉了一个原始作者最近停止维护的 React Native 派生框架项目。 The original author had made another project, which is an installer script for the framework.原作者制作了另一个项目,它是框架的安装程序脚本。 so I forked this too.所以我也分叉了这个。
The latter worked perfect, but the former one had a little problem, so I updated the framework's React Native version to latest.后者完美运行,但前者有一点问题,所以我将框架的 React Native 版本更新到最新版本。

But after updating, installer doesn't work.但更新后,安装程序不起作用。
Below is core part of the installer's main code.以下是安装程序主要代码的核心部分。 Full Code 完整代码

function installDesktopPackage() {
  let rndPackage = PACKAGE;

  console.log(`Installing ${rndPackage}...`);
  const pkgmgr = Common.isGlobalCliUsingYarn(process.cwd()) ? 'yarn add' : 'npm install --save';
  const execOptions = {stdio: 'inherit'}; // use {stdio: 'inherit'} for verbose
  execSync(`${pkgmgr} ${rndPackage}`, execOptions);
  console.log(chalk.green(`${rndPackage} successfully installed.`));
}

function runDesktopFilesGenerationScript() {

  const generateDesktop = require(REACT_NATIVE_DESKTOP_GENERATE_PATH());
  generateDesktop(process.cwd(), Common.getReactNativeAppName());
}

As you can see, installDesktopPackage should add framework files into local project, and runDesktopFilesGenerationScript should install files into right location.如您所见, installDesktopPackage应该将框架文件添加到本地项目中,并且runDesktopFilesGenerationScript应该将文件安装到正确的位置。

But when I ran installer code, this error occurs:但是当我运行安装程序代码时,会发生此错误:

Cannot find module '/home/jihoo/Desktop/test/node_modules/react-native-desktop-qt/local-cli/generate-desktop.js'                                                                                        
Require stack:                                                                                      
- /home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/src/cli.js              
- /home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/bin.js
Error: Cannot find module '/home/jihoo/Desktop/test/node_modules/react-native-desktop-qt/local-cli/generate-desktop.js'
Require stack:
- /home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/src/cli.js
- /home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/bin.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at runDesktopFilesGenerationScript (/home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/src/cli.js:34:27)
    at /home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/src/cli.js:44:5
    at Object.<anonymous> (/home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/src/cli.js:50:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/src/cli.js',
    '/home/jihoo/.npm/_npx/41097/lib/node_modules/react-native-desktop-qt-init/bin.js'
  ]
}

Yes, I found it that installDesktopPackage did not added any files, including {PROJECT_PATH}/node_modules/react-native-desktop-qt/local-cli/generate-desktop.js which is needed by runDesktopFilesGenerationScript是的,我发现installDesktopPackage没有添加任何文件,包括 runDesktopFilesGenerationScript 所需的{PROJECT_PATH}/node_modules/react-native-desktop-qt/local-cli/generate-desktop.js runDesktopFilesGenerationScript

So I tried yarn add and npm install --save manually, but both doesn't add any files to {PROJECT_PATH}/node_modules/所以我尝试了yarn addnpm install --save手动,但两者都没有将任何文件添加到{PROJECT_PATH}/node_modules/

I tried cleaning cache of npm and Yarn, and retried, but the result is same.我尝试清理 npm 和 Yarn 的缓存,并重试,但结果相同。

My specs are:我的规格是:
CentOS 8 CentOS 8
Qt 5.12.2 Qt 5.12.2
Node.js 14.15.4 LTS Node.js 14.15.4 LTS
npm 6.14.10 npm 6.14.10
Yarn 1.22.10纱线 1.22.10
React Native 0.63.4反应原生 0.63.4
react-native-cli 2.0.1反应原生 cli 2.0.1
JetBrains WebStorm 2020.3 JetBrains WebStorm 2020.3

I solved it.我解决了。 I accidently broke packages.json of my project so script was installing frameworks in wrong path.我不小心破坏了我项目的packages.json ,所以脚本以错误的路径安装框架。 I fixed it.我修好了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM