Last updated: Mar 7, 2024
Reading timeยท3 min
When you list the installed packages in your project, you might get an error "npm ERR! extraneous" or you might see the label "extraneous" next to package names.
npm ERR! extraneous: accepts@1.3.8 npm ERR! extraneous: array-flatten@1.1.1 npm ERR! not ok code 0
The issue occurs when a package is installed but is not listed in your project's
package.json
file.
The npm list command prints the
installed packages and their versions based on the contents of your
node_modules
directory.
node_modules
directory and the dependencies in your package.json
file, the extraneous
label is shown.You can resolve the issue by using the npm prune
command.
npm prune
The npm prune command removes extraneous packages.
These are the packages that are present in your node_modules
directory that
are not listed in your package.json
file.
You can issue the npm list
command to verify that the unnecessary packages
have been removed.
npm list
If the issue persists, delete your node_modules
and
package-lock.json files.
The following command deletes the files on Windows.
# ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock
The following command deletes the files on macOS and Linux.
# ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock
Run the following command to clean your npm cache.
# ๐๏ธ clean npm cache npm cache clean --force
And install the packages that are present in your package.json
file.
npm install
npm
If the issue persists, try updating your npm
version.
npm install -g npm@latest # ๐๏ธ If you get a permissions error on macOS / Linux sudo npm install -g npm@latest
If you get a permissions error on Windows, open CMD as an administrator and rerun the command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
npm install -g npm@latest npm install -g npm@latest --force
You can learn more about the related topics by checking out the following tutorials: