Reputation: 3589
I'm creating a npm package, that requires axios
.
When i import it in my react application i get
Module not found: Can't resolve 'axios' in '/Users/******/nodework/consume/node_modules/myModule'
I want the client to be able to install my package module, without having to install another dependency on their end. How would i do that give that im already using peerDepencies and devDependencies ?
for example this is my package.json for my module.
{
"name": "myModule",
"version": "1.6.4",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"axios": "^0.19.0"
},
"peerDependencies": {
"axios": "^0.19.0"
}
}
Upvotes: 4
Views: 7236
Reputation: 696
Peer dependencies lets developers who are using your library know they need to install those libraries themselves because the library you wrote is using it. They will get "missing peer dependency" warnings when they install your library and do not have those installed yet.
The dev dependencies are typically for build tools like webpack, compilers, etc.
Both peer and dev dependencies will not be installed when a developer installs your library.
The clients will have to do something like npm i your-library axios
to install both your library and the peer dependency.
If you want the developers to solely install your library without having to install extras on their own, like axios in this case, you will have to list is as a regular dependency.
{
"dependencies": {
"axios": "^0.19.0"
}
}
Cheers
Upvotes: 2