将npm降级为旧版本

时间:2017-09-25 22:54:08

标签: node.js npm installation downgrade

我尝试更新npm以查看它是否能解决我们遇到的一些依赖性问题,现在我想降级到开发团队其余部分正在使用的版本。如何安装旧版本?

我根据installation page

上的说明更新了npm
  

更新npm

     

Node安装了npm,因此你应该有一个npm版本。但是,npm比Node更频繁地更新,因此您需要确保它是最新版本。

     

class Step2VC: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var usersTableView: UITableView! var users = [User]() // create variable called 'users' which is an array of type User (which is a class we created) var firebaseUser: FIRUser! var firebaseStorage: FIRStorage! var ref: FIRDatabaseReference! var cellStyleForEditing: UITableViewCellEditingStyle = .none override func viewDidLoad() { super.viewDidLoad() navigationItem.title = "users" usersTableView.dataSource = self usersTableView.delegate = self usersTableView.tableFooterView = UIView() // -------- // Firebase // -------- firebaseUser = FIRAuth.auth()?.currentUser firebaseStorage = FIRStorage.storage() ref = FIRDatabase.database().reference().child("users").child(firebaseUser.uid) navigationItem.rightBarButtonItem = UIBarButtonItem(title: "edit", style: .plain, target: self, action: #selector(editButtonTapped)) loadExistingUsers() // check to see if there are existing users, and if so, load them into tableview } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true) usersTableView.reloadData() } // ---------- // Table View // ---------- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return users.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! Step2Cell cell.myLabel.text = users[indexPath.row].firstName cell.userImage.image = users[indexPath.row].photo return cell } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { deleteUserConfirmationAlert(tableViewIndexPath: indexPath) } } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { performSegue(withIdentifier: "EditUser", sender: users[indexPath.row]) } // ---------- // Navigation // ---------- override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "EditUser" { let nextContoller = segue.destination as! Step2UsersVC // 'sender' is retrieved from 'didSelectRow' function above nextContoller.user = sender as? User nextContoller.navBarTitle = "edit user" } else if segue.identifier == "AddUser" { let nextController = segue.destination as! Step2UsersVC nextController.navBarTitle = "add user" } else { print("Segue Initiated:",segue.identifier!) } } @IBAction func unwindToStep2VC(sender: UIStoryboardSegue) { let sourceVC = sender.source as! Step2UsersVC let updatedUser = sourceVC.user if let selectedIndexPath = usersTableView.indexPathForSelectedRow { // Update an existing user users[selectedIndexPath.row] = updatedUser! usersTableView.reloadData() } else { // Add a new user let newIndexPath = IndexPath(row: users.count, section: 0) users.append(updatedUser!) usersTableView.insertRows(at: [newIndexPath], with: .automatic) users.sort(by: {$0.birthday < $1.birthday}) usersTableView.reloadData() } } @IBAction func nextButtonTapped(_ sender: UIButton) { // check for at least two users if users.count < 2 { createAlert(alertTitle: "Users", alertMessage: "You have not created enough users. Please enter in at least two users.") } else { // check for at least one parent if numberOfParents() < 1 { createAlert(alertTitle: "Users", alertMessage: "You must have at least one parent. Please enter in a parent.") } else { confirmationAlert() } } } // --------- // Functions // --------- // if users exist on Firebase, load them func loadExistingUsers() { ref.child("members").observe(.childAdded) { (snapshot: FIRDataSnapshot) in if let dict = snapshot.value as? [String : Any] { let userPhotoUrl = dict["profileImageUrl"] as! String let userFirstName = dict["firstName"] as! String let userBirthday = dict["birthday"] as! Int let userPasscode = dict["passcode"] as! Int let userGender = dict["gender"] as! String let isUserChildOrParent = dict["childParent"] as! String let storageRef = FIRStorage.storage().reference(forURL: userPhotoUrl) storageRef.data(withMaxSize: 1 * 1024 * 1024, completion: { (data, error) in let pic = UIImage(data: data!) let user = User(profilePhoto: pic!, userFirstName: userFirstName, userBirthday: userBirthday, userPasscode: userPasscode, userGender: userGender, isUserChildOrParent: isUserChildOrParent) self.users.append(user) self.users.sort(by: {$0.birthday < $1.birthday}) self.usersTableView.reloadData() }) } } } func saveUsersToFirebase() { for user in users { let storageRef = FIRStorage.storage().reference().child("users").child(firebaseUser.uid).child("members").child(user.firstName) let profileImg = user.photo let imageData = UIImageJPEGRepresentation(profileImg, 0.1) // compress photos storageRef.put(imageData!, metadata: nil, completion: { (metadata, error) in if error != nil { return } // get Firebase image location and return the URL as a string let profileImageUrl = (metadata?.downloadURL()?.absoluteString)! // save user data to Firebase self.ref?.child("members").child(user.firstName).setValue(["profileImageUrl" : profileImageUrl, "firstName" : user.firstName, "birthday" : user.birthday, "passcode" : user.passcode, "gender" : user.gender, "childParent" : user.childParent]) }) } } func editButtonTapped() { if cellStyleForEditing == .none { cellStyleForEditing = .delete navigationItem.rightBarButtonItem = UIBarButtonItem(title: "done", style: .done, target: self, action: #selector(editButtonTapped)) } else { cellStyleForEditing = .none navigationItem.rightBarButtonItem = UIBarButtonItem(title: "edit", style: .plain, target: self, action: #selector(editButtonTapped)) } usersTableView.setEditing(cellStyleForEditing != .none, animated: true) } func deleteUserConfirmationAlert(tableViewIndexPath: IndexPath) { // create alert for user to confirm user deletion let alert = UIAlertController(title: "Delete User", message: "Are you sure you want to delete \(users[tableViewIndexPath.row].firstName)? This cannot be undone.", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "okay", style: .default, handler: { (action) in alert.dismiss(animated: true, completion: nil) // remove user from Firebase self.ref.child("members").child(self.users[tableViewIndexPath.row].firstName).removeValue() self.users.remove(at: tableViewIndexPath.row) self.usersTableView.deleteRows(at: [tableViewIndexPath], with: .fade) })) alert.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: { (action) in alert.dismiss(animated: true, completion: nil) self.usersTableView.reloadData() })) present(alert, animated: true, completion: nil) } func numberOfParents() -> Int { var parentCount = 0 for user in users { if user.childParent == "parent" { parentCount += 1 } } return parentCount } func createAlert(alertTitle: String, alertMessage: String) { let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "okay", style: .cancel, handler: { (action) in alert.dismiss(animated: true, completion: nil) })) present(alert, animated: true, completion: nil) } func confirmationAlert() { let alert = UIAlertController(title: "Users", message: "You have entered in \(users.count) users. Are you finished adding family members?", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "continue", style: .default, handler: { (action) in self.saveUsersToFirebase() self.performSegue(withIdentifier: "GoToStep3", sender: self) alert.dismiss(animated: true, completion: nil) })) alert.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: { (action) in alert.dismiss(animated: true, completion: nil) })) present(alert, animated: true, completion: nil) }

5 个答案:

答案 0 :(得分:109)

只需将npm install npm@latest -g替换为您要降级到的版本号即可。我想降级到版本3.10.10,所以我使用了这个命令:

@latest

如果您不确定应使用哪个版本,请查看version history。例如,您可以看到3.10.10是npm 3的最新版本。

答案 1 :(得分:16)

只需要添加你想要的版本

  

升级或降级

npm install -g npm @ version

示例如果你想从npm 5.6.0降级到4.6.1那么,

npm install -g npm@4.6.1

在linux上测试

答案 2 :(得分:2)

npm install -g npm@4

这将在主要版本4上安装最新版本,不需要指定版本号。将4替换为您想要的任何主要版本。

答案 3 :(得分:1)

Before doing that Download Node Js 8.11.3 from the URL: download

Open command prompt and run this:

npm install -g npm@3.10.10

use this version this is the stable version which works along with cordova 7.1.0

for installing cordova use : • npm install -g cordova@7.1.0

• Run command

• Cordova platform remove android (if you have old android code or code is having some issue)

• Cordova platform add android : for building android app in cordova Running: Corodva run android

答案 4 :(得分:0)

即使我跑npm install -g npm@4,也不适合我。

最后,我下载并安装旧的node.js版本。

https://nodejs.org/download/release/v7.10.1/

这是npm版本4.

您可以在此处选择任何版本 https://nodejs.org/download/release/