Your npm build is failing because it’s flagging packages that are no longer recommended for use, and npm’s default behavior is to warn and potentially halt the build.

Here’s how to diagnose and fix those deprecation warnings:

  • Cause 1: Outdated Dependencies The most common reason is that you’re using packages that have been superseded by newer, better versions.

    • Diagnosis: Run npm outdated. This will list all packages that have newer versions available, including those that are deprecated.
    • Fix: For each deprecated package listed by npm outdated, run npm update <package-name>. This will upgrade the package to its latest non-deprecated version. If a direct update isn’t possible or introduces breaking changes, you might need to manually change the version in your package.json and run npm install.
    • Why it works: npm update respects semantic versioning and your package.json’s version ranges. It pulls in the latest compatible, non-deprecated version, resolving the warning.
  • Cause 2: Direct Dependency Deprecation Sometimes, a package you directly depend on has been marked as deprecated by its author.

    • Diagnosis: Look for lines in your npm install or npm ci output that explicitly say <package-name>@<version> has been deprecated.
    • Fix: You’ll need to find a replacement. Check the npm registry page for the deprecated package; often, authors will suggest alternatives. If a replacement is suggested, update your package.json to use the new package and remove the old one, then run npm install.
    • Why it works: By switching to an actively maintained and non-deprecated alternative, you eliminate the source of the warning.
  • Cause 3: Transitive Dependency Deprecation A package you use depends on another package, and that dependency is deprecated. This is often harder to spot.

    • Diagnosis: Run npm ls. Look for (deprecated) next to package names. The output will show the dependency tree, so you can see which of your direct dependencies is bringing in the deprecated transitive one.
    • Fix: You can try to force an update of the transitive dependency if a newer, non-deprecated version exists and is compatible. Use npm update <deprecated-package-name> --depth=10 (adjust depth if needed, though 10 is usually sufficient). If that doesn’t work or the deprecated package is still the only option, you might need to "overlook" the deprecation warning for that specific package (see Cause 5).
    • Why it works: Updating the transitive dependency directly, or forcing npm to consider newer versions of it, can resolve the issue if a non-deprecated alternative is available and compatible.
  • Cause 4: Deprecation Due to Security Vulnerabilities A package might be deprecated because it has known security flaws.

    • Diagnosis: Run npm audit. This command specifically checks for security vulnerabilities, which often correlate with deprecation warnings.
    • Fix: npm audit fix will attempt to fix vulnerable dependencies by upgrading them. If it can’t automatically fix it, it will tell you which package is vulnerable and suggest manual updates or replacements. Treat this as a critical fix and prioritize it.
    • Why it works: npm audit fix leverages npm’s vulnerability database to find and apply patches or upgrades that address the security issues, often by moving to a non-deprecated version.
  • Cause 5: Intentional Deprecation for Specific Use Cases Some packages are deprecated but still functional for legacy systems or specific, niche purposes.

    • Diagnosis: The deprecation warning itself will often explain why it’s deprecated and if it’s still safe to use in certain contexts.
    • Fix: You can explicitly tell npm to ignore deprecation warnings for a specific package by adding an npm-legacy-dep flag in your .npmrc file: npm-legacy-dep=<package-name>. Alternatively, you can suppress all deprecation warnings by setting npm config set loglevel warn or npm config set loglevel error in your .npmrc or globally. This is generally not recommended as it hides important information.
    • Why it works: The npm-legacy-dep flag signals to npm that you’re aware of the deprecation and intend to use the package anyway, suppressing the warning. Changing the log level prevents npm from emitting deprecation messages at all.
  • Cause 6: Corrupted Node Modules or Lock File Rarely, the node_modules directory or your package-lock.json can become corrupted, leading to incorrect dependency resolution and spurious warnings.

    • Diagnosis: Compare the output of npm ls to your package.json. If there are discrepancies or you suspect corruption, proceed with the fix.
    • Fix: Delete your node_modules folder and your package-lock.json file, then run npm install. For a cleaner install, use npm ci after deleting node_modules (it requires a valid package-lock.json but will fetch exact versions).
    • Why it works: This forces npm to re-resolve and reinstall all dependencies from scratch, ensuring a clean slate and correct dependency tree.

After applying these fixes, run npm install and then npm build (or your usual build command) again. If you encounter further issues, they are likely unrelated to deprecation warnings.

The next error you’ll likely hit is a 404 Not Found on a package that was recently unpublished.

Want structured learning?

Take the full Nodejs course →