2

Currently, the package registry in the package-lock.json is http://registry.npm.taobao.org/.

package-lock.json:

{
  "name": "webpack",
  "version": "1.0.0",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "@types/clean-webpack-plugin": {
      "version": "0.1.0",
      "resolved": "http://registry.npm.taobao.org/@types/clean-webpack-plugin/download/@types/clean-webpack-plugin-0.1.0.tgz",
      "integrity": "sha1-xJillaQXSwoxPOQt5+UldcEi9aQ=",
      "dev": true,
      "requires": {
        "@types/webpack": "*"
      }
    },
    "@types/node": {
      "version": "9.4.0",
      "resolved": "http://registry.npm.taobao.org/@types/node/download/@types/node-9.4.0.tgz",
      "integrity": "sha1-uFoLzx4cyE60kBt+lpZq7cbweNE=",
      "dev": true
    },
    "@types/strip-bom": {
      "version": "3.0.0",
      "resolved": "http://registry.npm.taobao.org/@types/strip-bom/download/@types/strip-bom-3.0.0.tgz",
      "integrity": "sha1-FKjsOVbC6B7bdSB5CuzyHCkK69I=",
      "dev": true
    },
    // ...others
}

I want to replace all registries with the npm official registry https://registry.npmjs.org/ or any specific registry. Keep using the same versions of packages.

How can I do that?

Lin Du
  • 88,126
  • 95
  • 281
  • 483
  • Does this answer your question? [Override registry for installed packages in package-lock.json](https://stackoverflow.com/questions/62439074/override-registry-for-installed-packages-in-package-lock-json) – JBallin Oct 20 '22 at 05:02

1 Answers1

1

Found a solution from issue of yarn.

Before replacing the registries, let's check how many registries need to be replaced, I will check the number of taobao words to determine.

☁  v4 [master] ⚡  grep -o 'taobao' package-lock.json | wc -l
    1180

Since some registries' pattern like this:

"resolved": "https://registry.npm.taobao.org/@hapi/joi/download/@hapi/joi-15.1.1.tgz?cache=0&sync_timestamp=1603524515155&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40hapi%2Fjoi%2Fdownload%2F%40hapi%2Fjoi-15.1.1.tgz",

The other_urls query string contains the url address of the taobao registry. The // symbol for the https protocol is escaped, so I will just replace registry.npm.taobao.org instead of https://registry.npm.taobao.org.

Besides, I removed the old node_modules using rm -rf node_modules, later, I will install node modules after replacing the registry with the new one, re-run npm install and run my application to check if it works.

Now, replace the registry using the below Linux command:

sed -i -e "s#registry.npm.taobao.org#registry.npmjs.org#g" package-lock.json

Check:

☁  v4 [master] ⚡  grep -o 'taobao' package-lock.json | wc -l                                  
       0
☁  v4 [master] ⚡  grep -o 'npmjs' package-lock.json | wc -l
    1180

After re-install the node modules with the new registries, my project generated by create-react-app tool works fine.

Lin Du
  • 88,126
  • 95
  • 281
  • 483
  • 1
    Did you encounter error about "npm ERR! code EINTEGRITY npm ERR! sha1-xOu8KJ85kaAo1EdRy90RkYsXkQw= integrity checksum failed when using sha1: wanted sha1-xOu8KJ85kaAo1EdRy90RkYsXkQw= but got sha512-RrERod97Dnwqq49WNz8qo66ps0swYZDSb6rM57kN2J+aoyEAJfZ6bMx0sx/F9TIEX0xthPGCmeyiam/jXif0eA== sha1-zUTECrB6DHo23F6Zqs4eyk7CaQw=. (3446 bytes)" during the re-installation? I got stuck on it. – John Xiao Dec 06 '21 at 03:23
  • @JohnXiao Replace `wanted` integrity with `already acquired ` integrity as error message shows – liuliang Jun 06 '22 at 09:31