`yarn add` 和 `npm install --save` 都不会将包安装到本地项目
`yarn add` and `npm install --save` both does not install packages to local project
我fork了一个React Native衍生的框架项目,原作者最近停止维护了。原作者做了另外一个工程,是框架的安装脚本。所以我也分叉了这个。
后者完美运行,但前者有点问题,所以我将框架的React Native版本更新到最新。
但是更新后,安装程序不起作用。
下面是安装程序主要代码的核心部分。 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());
}
如您所见,installDesktopPackage
应该将框架文件添加到本地项目中,runDesktopFilesGenerationScript
应该将文件安装到正确的位置。
但是当我ran安装程序代码时,出现这个错误:
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'
]
}
是的,我发现installDesktopPackage
没有添加任何文件,包括runDesktopFilesGenerationScript
需要的{PROJECT_PATH}/node_modules/react-native-desktop-qt/local-cli/generate-desktop.js
所以我手动尝试了 yarn add
和 npm install --save
,但两者都没有向 {PROJECT_PATH}/node_modules/
添加任何文件
我尝试清理 npm 和 Yarn 的缓存,然后重试,结果还是一样。
我的规格是:
中央操作系统 8
Qt 5.12.2
Node.js 14.15.4 LTS
npm 6.14.10
纱线 1.22.10
反应本机 0.63.4
react-native-cli 2.0.1
JetBrains WebStorm 2020.3
我解决了。我不小心破坏了项目的 packages.json
,因此脚本在错误的路径中安装了框架。我修好了。
我fork了一个React Native衍生的框架项目,原作者最近停止维护了。原作者做了另外一个工程,是框架的安装脚本。所以我也分叉了这个。
后者完美运行,但前者有点问题,所以我将框架的React Native版本更新到最新。
但是更新后,安装程序不起作用。
下面是安装程序主要代码的核心部分。 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());
}
如您所见,installDesktopPackage
应该将框架文件添加到本地项目中,runDesktopFilesGenerationScript
应该将文件安装到正确的位置。
但是当我ran安装程序代码时,出现这个错误:
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'
]
}
是的,我发现installDesktopPackage
没有添加任何文件,包括runDesktopFilesGenerationScript
{PROJECT_PATH}/node_modules/react-native-desktop-qt/local-cli/generate-desktop.js
所以我手动尝试了 yarn add
和 npm install --save
,但两者都没有向 {PROJECT_PATH}/node_modules/
我尝试清理 npm 和 Yarn 的缓存,然后重试,结果还是一样。
我的规格是:
中央操作系统 8
Qt 5.12.2
Node.js 14.15.4 LTS
npm 6.14.10
纱线 1.22.10
反应本机 0.63.4
react-native-cli 2.0.1
JetBrains WebStorm 2020.3
我解决了。我不小心破坏了项目的 packages.json
,因此脚本在错误的路径中安装了框架。我修好了。