Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo/revert "npm audit fix"

Tags:

npm

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

> [email protected] 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! [email protected] build: `webpack --mode production`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
like image 618
SoreThursday Avatar asked Jun 10 '20 14:06

SoreThursday


People also ask

What happens when you run npm audit fix?

Else, to resolve the vulnerabilities automatically run npm audit fix command. As a result, it will execute a npm install command under the hood and will upgrade patch versions of the packages with issues.

Should I always run npm audit fix?

If no security vulnerabilities are found, this means that packages with known vulnerabilities were not found in your package dependency tree. Since the advisory database can be updated at any time, we recommend regularly running npm audit manually, or adding npm audit to your continuous integration process.

Can you undo an npm install?

And just as you can install a package from the npm library, you can uninstall it. To uninstall a package, you can use the command provided by npm for the purpose – npm uninstall . The way you uninstall a regular package or dependency is not the way you should uninstall a global package and a dev dependency, though.


1 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:

  • npm install
  • package.json
  • package-lock.json
  • npm-shrinkwrap.json

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! :)

like image 92
Helge Drews Avatar answered Dec 03 '22 13:12

Helge Drews