[英]how to install only package.json dependencies with their own versions by using npm install or yarn
I work on a new project, but I can't install packages correctly. 我在一个新项目上工作,但是无法正确安装软件包。 I used
npm install
, yarn
, npm install --only=dev
, but there aren't enough. 我使用了
npm install
, yarn
, npm install --only=dev
,但是还不够。 I also try like that deleting node_modules and package-lock.json. 我也尝试删除node_modules和package-lock.json。 The state was the same.
状态是相同的。
We use in the project babel's 6.x version. 我们在项目中使用babel的6.x版本。 Babel has a update, 7.x, I think I get the error because of version differences when I run
npm install
, npm install --only=dev
, yarn
. Babel的更新为7.x,我认为由于运行
npm install
, npm install --only=dev
, yarn
时的版本差异而出现错误。
npm WARN deprecated babel-preset-es2015@6.24.1: Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
npm WARN不建议使用babel-preset-es2015@6.24.1: 感谢使用Babel:我们建议立即使用babel-preset-env:请阅读babeljs.io/env进行更新! npm notice created a lockfile as package-lock.json.
npm通知创建了一个作为package-lock.json的锁文件。 You should commit this file.
您应该提交此文件。 npm WARN babel-loader@8.0.4 requires a peer of @babel/core@^7.0.0 but none is installed.
npm WARN babel-loader@8.0.4需要一个对等体@ babel / core @ ^ 7.0.0,但没有安装。 You must install peer dependencies yourself.
您必须自己安装对等依赖项。 npm WARN babel-loader@8.0.4 requires a peer of webpack@>=2 but none is installed.
npm WARN babel-loader@8.0.4需要一个webpack @> = 2的同位体,但未安装。 You must install peer dependencies yourself.
您必须自己安装对等依赖项。
I use WebStorm. 我使用WebStorm。 Before that, I tried to get package for another project with npm install.
在此之前,我尝试通过npm install获得另一个项目的软件包。 "Npm" is not successful.
“ Npm”不成功。 WebStorm advice me using Yarn, and I used Yarn.
WebStorm使用纱来建议我,而我使用纱。 It was worked.
它工作了。
What should I do in the state? 在该州我该怎么办?
After npm install
, when I run parcel index.html
, I get the console error npm install
后,运行宗地parcel index.html
,出现控制台错误
"Uncaught TypeError: window.fooes is not a constructor", Uncaught ReferenceError: regeneratorRuntime is not defined.
“未捕获的TypeError:window.fooes不是构造函数”,未捕获的ReferenceError:未定义regeneratorRuntime。
I know that the code doesn't have a problem, because project work on the team's computer correctly. 我知道代码没有问题,因为项目可以在团队的计算机上正常工作。
The first and most important: 首先也是最重要的:
Never use npm
and yarn
at the same time. 切勿同时使用
npm
和yarn
。 Choose one of them and use that only because they are both using lock files based on the installed packages. 选择其中之一并仅使用它们是因为它们都基于已安装的软件包使用了锁定文件。
Which one to use: 使用哪个:
npm
and yarn
are both using the NPM software registry database. npm
和yarn
都使用NPM软件注册表数据库。 So in the end the final result when installing packages are the same, but yarn
does the job much-much faster. 因此,最终,安装卷装的最终结果是相同的,但是
yarn
的工作要快得多。 Yarn
was developed by Facebook because the slowness of npm
. Yarn
是由Facebook开发的,因为npm
的速度npm
。 So I prefer yarn
, I'm not using npm
commands anymore. 所以我更喜欢
yarn
,我不再使用npm
命令了。
To your problem: 给你的问题:
package-lock.json
and yarn.lock
lock files in your project root directory. package-lock.json
和yarn.lock
锁定文件。 node_modules
directory. node_modules
目录。 package.json
file. package.json
文件。 Make a backup of this file! package.json
and I suggest you to first delete all entries from it related to Babel
and save it. package.json
,我建议您首先从中删除与Babel
相关的所有条目并保存。 yarn
command (without params) in the project root (where your package.json
file is). package.json
文件所在的位置)中运行yarn
命令(无参数)。 This should install all your packages again. Then install the latest packages of Babel
using these commands: 然后使用以下命令安装最新的
Babel
软件包:
yarn add -D @babel/core
yarn add -D @babel/preset-env
yarn add -D babel-loader
You may need other packages from Babel
. 您可能需要
Babel
其他软件包。 Have a look on your backed up package.json
and search for the latest versions in the npm registry or Babel's plugins documentation page for the remaining plugins (if any). 查看您备份的
package.json
并在npm注册表或Babel的插件文档页面中搜索最新版本,以查找剩余的插件(如果有)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.