9

My package.json file looks like so:

{
  "name": "Orignal Name",
  "version": "0.0.1",
  "description": "An App",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "engines": {
    "node": "0.10.x",
    "npm": "1.3.x"
  },
  "author": "An author",
  "license": "BSD-2-Clause",
  "dependencies": {
    "jade": "~0.35.0",
    "express": "~3.4.4",
    "stylus": "~0.40.2",
    "mongoose": "~3.8.0",
    "passport-local": "~0.1.6",
    "passport": "~0.1.17"
  },
  "devDependencies": {
    "karma-mocha": "~0.1.0",
    "mocha": "~1.14.0",
    "karma-chai-plugins": "~0.1.3",
    "karma-firefox-launcher": "~0.1.0",
    "karma-chrome-launcher": "~0.1.0",
    "karma-script-launcher": "~0.1.0",
    "karma-html2js-preprocessor": "~0.1.0",
    "karma-jasmine": "~0.1.3",
    "requirejs": "~2.1.9",
    "karma-requirejs": "~0.2.0",
    "karma-coffee-preprocessor": "~0.1.0",
    "karma-phantomjs-launcher": "~0.1.0",
    "karma": "~0.10.5"
  }
}

How do I change the "name": attribute "Original Name" to "New Name" without breaking npm install ?

I tried simply updating the name and attempting npm install but npm install won't read the package.json file now.

Thanks in advance

9
  • 2
    From npm doc, you can t have url unsafe character, take the name of any already existing package, nor have dots or slash. Are thoses condition respected for the new name?
    – DrakaSAN
    Commented Sep 25, 2014 at 13:21
  • Yes those conditions are satisfied. Both names have the same format of characters only without spaces and both are unique to any name on the system. Commented Sep 25, 2014 at 13:23
  • And unique to all npm?
    – DrakaSAN
    Commented Sep 25, 2014 at 13:24
  • Yes, Unique to npm and all dependencies. Commented Sep 25, 2014 at 13:25
  • Did you change the version too?
    – DrakaSAN
    Commented Sep 25, 2014 at 13:25

2 Answers 2

10

just edit the name in package.json. The name must following the rules https://docs.npmjs.com/files/package.json#name

3
  • 1
    Does this break anything with databases or deployment or iOS or Android deployment
    – Mars2024
    Commented Oct 25, 2021 at 19:26
  • 3
    how gets the name in the package-lock.json updated??
    – jasie
    Commented Apr 8, 2022 at 13:02
  • 🎉 You got 10 points! 😉
    – tebkanlo
    Commented Dec 12, 2023 at 10:05
2

Just change the name in package.json file. Changes to the package should come along with changes to the version.

Once you change the name in package.json, the name and/or version properties in package-lock.json should also be changed. This can be done by simply running npm install

From npm docs

Some rules:

  • The name must be less than or equal to 214 characters. This includes the scope for scoped packages.
  • The names of scoped packages can begin with a dot or an underscore. This is not permitted without a scope.
  • New packages must not have uppercase letters in the name.
  • The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can't contain any non-URL-safe characters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.