Force specific version of nested dependency in NPM package

I’m trying to work with the eslint-plugin-react package but running into issues with its dependencies. The dependency tree shows:

─┬ [email protected]
 │ ├─┬ [email protected]
 │ │ ├─┬ [email protected]

There’s a known issue with this particular acorn version that causes problems on Windows systems. The bug is resolved in newer releases.

Is there a way to force eslint-utils to use an updated version of acorn?

Here’s what I know:

  • The eslint-plugin-react package specifically needs version "~2.1.0" of eslint-utils, and that version locks acorn to "~7.4.0"
  • Simply adding acorn to my main package.json doesn’t work because NPM installs both versions and the plugin still uses the problematic one.

drop a .npmrc file in your project root with legacy-peer-deps=true - it’ll make npm handle nested dependency conflicts differently. also worth checking if there’s a resolutions field you can use. works like overrides but plays nicer with older npm versions.

NPM dependency conflicts are the worst. I’ve been there with nested dependencies causing total headaches.

Sure, you could try npm overrides or yarn resolutions, but they’re flaky and break when you update.

Here’s what actually works - automate the whole thing. Build a workflow that watches your dependencies, catches conflicts early, and handles updates automatically.

I did this with Latenode when React testing library kept breaking our builds. The automation spots problematic versions, creates PRs with fixes, and runs tests to make sure nothing’s broken.

Set up a workflow that:

  • Watches package.json for bad dependency combos
  • Auto-applies overrides or patches
  • Alerts you when it needs manual help
  • Tracks which versions play nice together

No more manual fighting with this stuff. It runs in the background and only bugs you when something actually needs your input.

The overrides approach works, but it gets messy with complex dependency chains. I’ve had better luck with patch-package for a permanent fix. Install patch-package, manually update the acorn version in node_modules, test that everything works, then run npx patch-package eslint-utils. This creates a patch file in your patches directory. What’s great is it survives npm installs and works the same across all environments, including CI/CD. I’ve used this for similar Windows bugs in nested dependencies. The patch applies automatically when anyone installs dependencies, so your whole team gets the fix without remembering extra config steps. Just commit the patches directory to your repo.

Manual overrides work but you’re stuck playing whack-a-mole every time dependencies update. I’ve dealt with this across dozens of microservices - it gets old fast.

Automated dependency management solved it for me. Instead of fixing conflicts manually, I built a system that handles this stuff automatically.

My setup monitors vulnerabilities, catches version conflicts, and applies fixes without me touching anything. When it hits something like your acorn issue, it automatically tests different version combos until one works.

Best part? It learns from previous fixes. Solve an acorn conflict once, it remembers that pattern for future projects.

I use Latenode to orchestrate everything. It connects npm audit, testing pipelines, and git operations into one workflow. Takes maybe an hour to set up but saves weeks of manual dependency wrestling.

The automation runs daily checks, creates fix branches when needed, and only pings me when something actually needs human judgment.

You can resolve the issue with nested dependencies by using npm’s overrides feature. This allows you to specify a replacement version for the conflicting package directly in your package.json. Here’s how to do it:

{
  "overrides": {
    "eslint-plugin-react": {
      "eslint-utils": {
        "acorn": "^8.0.0"
      }
    }
  }
}

This configuration tells npm to use version 8.x of acorn, thus bypassing the problematic 7.4.1 version when it is required through eslint-plugin-react. After adding this, make sure to delete your node_modules folder and the package-lock.json file, then run npm install again. I’ve successfully used this method before, and it should work effectively without affecting other dependencies, but always verify that everything operates smoothly afterward.

I hit the same dependency hell with Windows-specific bugs in nested packages. Fastest fix I found was npm shrinkwrap to lock versions after manually tweaking node_modules. Go to node_modules/eslint-utils and edit package.json - change "acorn": "~7.4.0" to "acorn": "^8.0.0" so it accepts newer acorn versions. Delete the eslint-utils node_modules folder and run npm install from that directory. After you confirm the newer acorn version works, run npm shrinkwrap from your project root. This creates npm-shrinkwrap.json that locks your exact dependency tree. It’s manual but you get precise control over what’s installed. I’ve done this when overrides weren’t available or just didn’t work. Just remember to update the shrinkwrap file when you change other dependencies.