<- Back

Important NPM commands

  • npm i xyz
  • npm i -D pqr - install dev dependencies
  • npm list - see versions of every package installed
  • npm list --depth=2 - Show package dependency tree with depth of 2
  • npm show next version - Show latest version of package available in remote repo

Scoped packages

what is a scoped package - This is used to group the packages under specific organization e.g. We have this package created by netlify team @netlify/plugin-nextjs If other organization wants to create a package with same name that's possible. e.g. @vercel/plugin-nextjs Here even though package names are same, they have different scope and codebase.

Prefix modifiers of NPM packages

what is prefix modifiers like ^ and ~ in the package version

  • ^ symbol specified that package can be updated as long as major version is below e.g. "postcss": "^8.4.4" - In this case, package will be updated but below version 9.x.x
  • ^ symbol specified that package can be updated as long as minorversion is below e.g. "netlify-plugin-cypress": "~2.2.0" - In this case, package will be updated but below version 2.3.x

dependencies

There are 3 types of dependencies

  • dependencies
  • devDependencies
  • peerDependencies

e.g. If you have a dependency "next-mdx-remote" in a project. But if you look at the "next-mdx-remote" package.json file, you will see that below peerDependencies are mentioned.

"peerDependencies": { "react": ">=16.x <=17.x", "react-dom": ">=16.x <=17.x" },

So you will need to install the react version that is between version 16 and 17. If you install react version that is not matching with above, it will throw error saying "unable to resolve dependency tree".

You can fix the error by passing below flags --legacy-peer-deps: ignore all peerDependencies --strict-peer-deps: fail and abort the install process for any conflicting peerDependencies --force: will force npm to fetch remote package forcefully.

package-lock.json file

lockfile keeps track of the exact versions of all the installed packages and their dependencies in a Node.js project.

Web development and Automation testing

solutions delivered!!