
When you develop a project with npm, you will probably write the dependencies in the package.json file.
When I publish my own npm packages, I write down the dependencies, devDependencies, and peerDependencies. The following is a list of dependencies and their effects that I checked.
This is what I imagine a package to look like.
The project created when developing is called the node.js Parent project, and the necessary libraries are called Child projects.
For example, when using the jQuery library, that is a child project.
Write the external packages required for the project.
The required libraries listed in the dependencies section of the package.json of the child project (e.g. jQuery) will be installed automatically. They will be automatically installed and placed in the node_modules folder in the parent project.
You can use npm install <package-name>
to install the libraries needed to run your project.
npm will automatically add them to the package.json file.
You can write a package that is only needed when developing the package itself.
When you create a library that can be used by various projects and release it to the public, you will probably develop the child projects in the figure.
The user (the parent project) may not want to install test libraries or build tools that are only needed when developing the child project.
The libraries that are used only for development should be written in the devDependencies section.
In my case, package.json contains libraries necessary for executing test code such as jest and Jasmine, tools necessary for checking operation, build tools, etc.
You can manually add it to package.json and install it using the npm install
command or by specifying the package to be used for development with the option "--save-dev" as in npm install <package-name> --save-dev
.
The package.json file will be updated and appended.
This is useful if you have created your own npm package and want to use it from another project.
Specify the prerequisite packages that are required to run this package (packages that should be installed in the parent project when used). If you are using npm ver.3 or later, when you install the npm package with peerDependencies, it will warn you if any of the libraries listed in this field are not installed. It will not install the parent package by itself.
For example, the npm package "gatsby-remark-text-decoration" assumes that the Gatsby static site generator package is installed, so the package.json is written as shown below.
"peerDependencies": {
"gatsby": "^2.0.0"
},
If you try to install this package without having installed Gatsby (npm install), you will get a warning message as shown below.
> npm install gatsby-remark-text-decoration
npm WARN gatsby-remark-text-decoration@1.0.5 requires a peer of gatsby@^2.0.0 but none is installed. You must install peer dependencies yourself.
WARN gatsby-remark-text-decoration@1.0.5 requires a peer of gatsby@^2.0.0 but none is installed. You must install peer dependencies You must install peer dependencies WARN requires a peer of gatsby@^2.0.0 but none is installed. If you want to use it, you'll have to install it manually by yourself . If you want to use it, you have to install it manually yourself.
I feel much better about using dependencies, devDependencies, and peerDependencies, which I was unclear about until I created my own npm package!
docs.npmjs.com - Specifying dependencies and devDependencies in a package.json file
docs.npmjs.com - package-json - peerdependencies
Github - gatsby-remark-text-decoration
Update | Modification |
---|---|
None |
Thank you for your message.
Sorry. The Error has occurred.We apologize for the inconvenience.Please try again in a few minutes or contact us via DM below.
Twitter:@NodachiSoft_engName:Send the following information to us. If you are happy with your submission, please click "Send". If you want to modify it, please click "Back".
Name: