I’m working with an Angular 16 project and running into a strange issue. When I install dependencies using npm install and then start the dev server with ng serve, everything works perfectly fine.
However, when I clean install using npm ci and try to run ng serve afterwards, I get this error:
SyntaxError: Named export 'locatePath' not found. The requested module 'locate-path' is a CommonJS module
The error seems to be coming from the find-up package that’s used by pkg-dir. When I check the dependency tree with npm ls locate-path, I can see it’s pulled in through @angular-devkit/build-angular.
I’ve tried forcing specific versions of both find-up and locate-path in my package.json overrides section, but nothing seems to work. The error only happens after using npm ci - regular npm install works fine.
Has anyone encountered this module resolution issue before? What’s the difference in how npm ci handles these CommonJS/ESM dependencies compared to regular npm install?
This happens when your package-lock.json doesn’t match what npm ci expects. npm ci installs exactly what’s in the lockfile - no flexibility. npm install can resolve conflicts differently. I hit this same issue on a work project where the lockfile was created with a different Node version. Delete both node_modules and package-lock.json, then run npm install to get a fresh lockfile. If it works, commit the new package-lock.json. Also double-check your Node version matches whoever originally created the lockfile - ESM/CommonJS resolution changes between versions.
I’ve hit this exact issue with Angular projects. npm ci does a strict install from package-lock.json without any dependency resolution, while npm install can tweak versions to fix conflicts. That locate-path error screams version mismatch - what’s locked doesn’t match what Angular CLI wants for ESM imports. Check if your package-lock.json got generated with a different npm version. npm 7+ handles peer dependencies way differently than npm 6. Try upgrading npm first with npm install -g npm@latest, then regenerate the lockfile. Also seen corporate environments and CI systems mess with module resolution through npm configs. Double-check your .npmrc settings match between working and broken environments.
i had a similar issue once! clearing the cache helped me too. sometimes the cache gets corrupted and causes all sorts of problems. make sure your dependencies are up to date and try running npm ci again after that! good luck!