How to undo/revert "npm audit fix"

Viewed 14861

As the title says. I have run npm audit fix in cmd. Now I can't run npm run build as it gives me errors. How to undo npm audit fix? Is there such command?

After running npm audit fix I get this errors:

D:\SUBLIME\REACT>npm run build

> uploadpublish@1.0.0 build D:\SUBLIME\REACT
> webpack --mode production

D:\SUBLIME\REACT\node_modules\webpack-cli\bin\config-yargs.js:136
                                describe: optionsSchema.definitions.output.properties.path.description
                                                                           ^

TypeError: Cannot read property 'properties' of undefined
    at module.exports (D:\SUBLIME\REACT\node_modules\webpack-cli\bin\config-yargs.js:13
    at D:\SUBLIME\REACT\node_modules\webpack-cli\bin\webpack.js:59:27
    at Object.<anonymous> (D:\SUBLIME\REACT\node_modules\webpack-cli\bin\webpack.js:514
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! uploadpublish@1.0.0 build: `webpack --mode production`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the uploadpublish@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\VERYNICE\AppData\Roaming\npm-cache\_logs\2020-06-10T14_43_53_493Z-debug.log
3 Answers

Unfortunately, an undo function does not exist in npm, so keeping the previous state of the package.json file and, if present, the package-lock.json and the npm-shrinkwrap.json (these files are optionally) to restore it via npm install (or short: npm i) is the way to go.

Normally, in a situation like yours, you would simply revert all changes to package.json and package-lock.json with a version control system like git. Of course, you can do this manually, too, if you have saved the previous version of these files somewhere. A present npm-shrinkwrap.json file is not affected by an npm update and therefor must not be restored.

Afterwards you can install the old version of your project's dependencies with npm i. Keep in mind, that the package-lock.json takes precedence over package.json and the package.json file uses Semantic Versioning (semver). And the npm-shrinkwrap.json file takes precedence over both files. There are even some more subtle differences, but I think this goes too far for this answer.

For more details, you can refer to these docs:

So I hope you have a backup or a previous git commit somewhere. Otherwise you could try to resolve the error by trying to read the error message and use an older version of the package which throws this error (webpack in you case). Also the dependencies of this package could be the reason for the problem. But take your time, if you decide to go this way. Good luck! :)

I had a slightly different problem. I ran npm audit fix --force while developing my app, and my project failed to compile when I tried to run npm start. I saw the previous answer, and found more information about npm auditin this article on Overreacted.

I ran git status to make sure the changes to package.json and package-lock.json were not yet staged for commit. Then, I ran git restore package-lock.json and git restore package.json. Then, I ran npm install again, and the app was able to compile.

I manually copied my package.json and package.lock.json from my previous commit, then I did an 'npm install' and rebuilt my React native app. It worked perfectly!

Related