npm install compile times "Cannot read properties of null (reading 'pickAlgorithm')"

Look at the error first:
insert image description here

Let me talk about most of the solutions on the Internet:
Option 1:

Reinstall node to solve

Option II:

Deleted the node models and re-downloaded

Or directly download CNPM (Taobao Mirror) to install CNPM installation method

npm install -g cnpm -registry=https://registry.npm.taobao.org

Check whether cnpm is installed successfully cnpm -v

third solution:

Clear the cache npm cache clear --force and then reinstall the dependency npm install

My solutions
are basically the above three methods. Let me first talk about why this error occurs in my project. The project originally used node13 and 14 versions. Then we upgraded node to 16 and found all the original projects. Can't compile, all report this kind of error.
The illusion encountered during the test, when upgrading node13 to 16, recompile, the compilation is normal, but later found that when node_modules is deleted and recompiled, the above error will appear, the reason may be that the node_modules compiled by node13 does not have Delete, the project has been reading the node13 compiled stuff, giving us the idea that our installation of node16 was successful.

When encountering this kind of problem, which involves node upgrade, the above solutions have not been able to solve it.

Finally the solution, find package-lock.jsonthe file. Keep the red circled content in the picture, delete all the rest, and then npm installrecompile, package-lock.json will generate a new file. Finally compiled successfully. be resolved.
insert image description here

Summary : The structure of package-lock.json generated by node13 may have undergone major changes from the structure of package-lock.json of node16. So we use the package-lock.json generated by node13 to let node16 parse it, it must not be parsed. We deleted all the content, and node16 generated a new content for us. In theory, it will not affect our project, because the versions of the various packages we use are defined in package.json, and the version dependencies in the generated package-lock.json are also generated with reference to package.json, and Does not affect the use of the overall framework.

Guess you like

Origin blog.csdn.net/weixin_43865196/article/details/125254459