Fix to The “npm ERR! Object for dependency @Babel/generator is empty” Error

Karan S. Chauhan
3 min readSep 30, 2020

--

I’m currently in the process of completing my Mod 4 project at Flatiron’s software engineering bootcamp. After some time doing research and implementing code I suddenly ran into an odd error that I hadn’t come across before.

I didn’t quite understand this error as everything was working just fine moments before. I tried to enter “npm install” but this same error would come up.

After some time on Google, I found that the solution was very simple.

All I had to do was clear the node_modules and package-lock.json. You can do so with the following line of code in the terminal:

The issue was fixed but I was still curious about what the second part of the error mentioned.

“If using a shrinkwrap, regenerate with npm shrinkwrap.”

I wanted to know what this meant.

Package-lock.json and npm-shrinkwrap.json are very similar. They both hold information about the dependencies that were installed for the application.

Some of the differences are:

  1. package-lock.json can be ignored in github if it isn’t in the top-level package.
  2. npm-shrinkwrap.json is essentially the same file, however this can be published onto github.
  3. If, for some reason, an app has both package-lock.json & npm-shrinkwrap.json, the package-lock.json file will be ignored.
  4. npm-shrinkwrap.json is compatible with the older versions of npm, 2–4.

If the package is going to be published to the npm database, then there are a couple more key differences:

  • Using a package-lock.json file will record which dependency versions were initially installed. Also, it will allow others to use different versions of the dependencies that are compatible (noted from version ranges in the package-lock.json file)
  • Using an npm-shrinkwrap.json file will ensure that anyone who downloads the package will need to install the same version of the dependencies that were included for the package.

RESOURCES:

https://stackoverflow.com/questions/63321707/react-npm-install-fails

https://medium.com/@suneetbansal/npm-shrinkwrap-nice-efficient-way-of-dependencies-version-locking-way-efd59ac35605

https://docs.npmjs.com/configuring-npm/package-lock-json.html

--

--