Skip to content

Instantly share code, notes, and snippets.

@davesag
Last active August 29, 2015 14:02
Show Gist options
  • Save davesag/d128e0afbe2342fc5191 to your computer and use it in GitHub Desktop.
Save davesag/d128e0afbe2342fc5191 to your computer and use it in GitHub Desktop.
Upgrading from Sails.js 0.9 to 0.10 - Notes

Upgrading Sails.js to v0.10

First I had some issues finding how to actually upgrade it, but google soon pointed me at

http://stackoverflow.com/questions/23277697/do-i-need-to-do-anything-special-to-my-application-built-with-sails-version-0-9

which suggested running

npm update sails -g

This failed with error

> npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/sails/.npmignore'
> npm ERR! error rolling back  [email protected] { [Error: EACCES, unlink '/usr/local/lib/node_modules/sails/.npmignore']
> npm ERR! error rolling back   errno: 3,
> npm ERR! error rolling back   code: 'EACCES',
> npm ERR! error rolling back   path: '/usr/local/lib/node_modules/sails/.npmignore' }
> npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/sails/.npmignore'
> npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/sails/.npmignore']
> npm ERR!   errno: 3,
> npm ERR!   code: 'EACCES',
> npm ERR!   path: '/usr/local/lib/node_modules/sails/.npmignore' }
> npm ERR! 
> npm ERR! Please try running this command again as root/Administrator.
> 
> npm ERR! System Darwin 13.2.0
> npm ERR! command "node" "/usr/local/bin/npm" "update" "sails" "-g"
> npm ERR! cwd /Users/davesag/src/myProject/test
> npm ERR! node -v v0.10.28
> npm ERR! npm -v 1.4.13
> npm ERR! path /usr/local/lib/node_modules/sails/.npmignore
> npm ERR! code EACCES
> npm ERR! errno 3
> npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/sails/.npmignore'
> npm ERR! 
> npm ERR! Additional logging details can be found in:
> npm ERR!     /Users/davesag/src/myProject/test/npm-debug.log
> npm ERR! not ok code 0

Some more googling which suggested I upgrade Node so

brew update
brew doctor
brew upgrade node

This upgraded my node install to 0.10.28

Tried again and got the same errors, so then I just went for

sudo npm update sails -g

This worked, updating me to [email protected]

I updated my package.json file

npm install

> npm ERR! Error: EACCES, open '/Users/davesag/.npm/express/3.4.3/package/package.json'
> npm ERR!  { [Error: EACCES, open '/Users/davesag/.npm/express/3.4.3/package/package.json']
> npm ERR!   errno: 3,
> npm ERR!   code: 'EACCES',
> npm ERR!   path: '/Users/davesag/.npm/express/3.4.3/package/package.json',
> npm ERR!   parent: 'sails' }
> npm ERR! 
> npm ERR! Please try running this command again as root/Administrator.
> 
> npm ERR! System Darwin 13.2.0
> npm ERR! command "node" "/usr/local/bin/npm" "install"
> npm ERR! cwd /Users/davesag/src/myProject/test
> npm ERR! node -v v0.10.28
> npm ERR! npm -v 1.4.13
> npm ERR! path /Users/davesag/.npm/express/3.4.3/package/package.json
> npm ERR! code EACCES
> npm ERR! errno 3
> npm ERR! stack Error: EACCES, open '/Users/davesag/.npm/express/3.4.3/package/package.json'
> npm ERR! 
> npm ERR! Additional logging details can be found in:
> npm ERR!     /Users/davesag/src/myProject/test/npm-debug.log
> npm ERR! not ok code 0

I figured this would just go on all day so I decided to completely uninstall node

brew uninstall node

I then reset the ownership of all the folders in ~/.npm

sudo chown -R davesag ~/.npm/*

Reinstalled node

brew install node

then in my project folder tried npm install again.

That worked but I got this deprecation warning

> npm WARN deprecated [email protected]: DEPRECATED. See readme: https://github.com/gruntjs/grunt-lib-contrib

ran sails lift

> warn: The adapter `sails-mongo` appears to be designed for an earlier version of Sails.
> warn: (it has a `registerCollection()` method.)
> warn: Since you're running Sails v0.10.x, it probably isn't going to work.
> warn: To attempt to install the updated version of this adapter, run:
> warn: npm install [email protected]
> error: There was an error attempting to require("sails-mongo")
> error: Is this a valid Sails/Waterline adapter?  The following error was encountered ::
> error: Adapter is not compatible with the current version of Sails.

ran npm install [email protected] --save

That worked

Ran sails lift

> debug: Deprecated:   `config.adapters.default`
> debug: See http://links.sailsjs.org/docs/config/connections
> debug: (⌘ + double-click to open link from terminal)
> debug: For now, I'll pretend you set `config.models.connection`.
> 
> debug: Deprecated:   `config.adapters`
> debug: See http://links.sailsjs.org/docs/config/connections
> debug: (⌘ + double-click to open link from terminal)
> debug: For now, I'll pretend you set `config.connections`.
> 
> debug: Deprecated:   `config.adapters.*.module`
> debug: See http://links.sailsjs.org/docs/config/connections
> debug: (⌘ + double-click to open link from terminal)
> debug: For now, I'll pretend you set `config.connections["mongo"].adapter`.
> 
> debug: Deprecated:   `sails.config[500]`
> debug: See http://links.sailsjs.org/config/responses
> debug: (⌘ + double-click to open link from terminal)
> debug: sails.config[500] (i.e. `config/500.js`) has been superceded in Sails v0.10.
> debug: Please define a "response" instead. (i.e. api/responses/serverError.js)
> debug: Your old handler is being ignored. (the format has been upgraded in v0.10)
> 
> debug: Deprecated:   `sails.config[404]`
> debug: See http://links.sailsjs.org/config/responses
> debug: (⌘ + double-click to open link from terminal)
> debug: Please define a "response" instead. (i.e. api/responses/notFound.js)
> debug: Your old handler is being ignored. (the format has been upgraded in v0.10)
> debug: Received BTC to AUD rate data. Sat, 31 May 2014 03:16:18 -0000. Bid price is $654.82

TypeError: Object [object Object] has no method 'done'

Googled and found balderdashy/sails#1606

'.done was deprecated in 0.9 and will be removed in 0.10. You should use .exec in 0.10.x.'

Went throught my project and changed all .done with .exec

sails lift now works but my first attempt to run a page causes errors in my Utilities.showLogin(req) method.

exports.showLogin = function(req) {
  if (req.isAuthenticated()) return false;
  if (req.target.controller === 'passport' && req.target.action === 'login') return false;
  return true;
};

found balderdashy/sails#1372 that suggests changing req.target to req.options

That didn't work

found http://stackoverflow.com/questions/21514822/get-sails-request-target-from-policy-scope/21683181#21683181

which seems like overkill!

Just commented out the if (req.target.controller === 'passport' && req.target.action === 'login') return false; line for now as it's only used to decide whether to show the login button or not. I'll deal with that later.

sails lift

everything seems to work but I have to look into these deprecation warnings

> debug: Deprecated:   `config.adapters.default`
> debug: See http://links.sailsjs.org/docs/config/connections
> debug: (⌘ + double-click to open link from terminal)
> debug: For now, I'll pretend you set `config.models.connection`.
> 
> debug: Deprecated:   `config.adapters`
> debug: See http://links.sailsjs.org/docs/config/connections
> debug: (⌘ + double-click to open link from terminal)
> debug: For now, I'll pretend you set `config.connections`.
> 
> debug: Deprecated:   `config.adapters.*.module`
> debug: See http://links.sailsjs.org/docs/config/connections
> debug: (⌘ + double-click to open link from terminal)
> debug: For now, I'll pretend you set `config.connections["mongo"].adapter`.
> 
> debug: Deprecated:   `sails.config[500]`
> debug: See http://links.sailsjs.org/config/responses
> debug: (⌘ + double-click to open link from terminal)
> debug: sails.config[500] (i.e. `config/500.js`) has been superceded in Sails v0.10.
> debug: Please define a "response" instead. (i.e. api/responses/serverError.js)
> debug: Your old handler is being ignored. (the format has been upgraded in v0.10)
> 
> debug: Deprecated:   `sails.config[404]`
> debug: See http://links.sailsjs.org/config/responses
> debug: (⌘ + double-click to open link from terminal)
> debug: Please define a "response" instead. (i.e. api/responses/notFound.js)
> debug: Your old handler is being ignored. (the format has been upgraded in v0.10)

just found http://beta.sailsjs.org/#/documentation/reference/Upgrading

fixed my User.beforeValidate method

https://github.com/uncletammy/sails-generate-serverResponse 404s

created a new project to copy the default responses over

copied the api/responses folder over took a look at the Gruntfile.js and associated tasks folder - will deal with that later

copied the details from app.js over copied over bits and pieces from package.json

copied over config/connections.js and merged my mongo settings from config/adapters.js to copied over config/models.js and changed default to mongo copied over config/blueprints.js and config/globals.js deleted config/controllers.js moved most stuff over from config/sockets.js but set 'backwardsCompatibilityFor0.9SocketClients': true until I work out what's new with socket.io.js

Everything seems to work but now one of my tests is failing with a validation error saving a user.

Weirdly the beforeValidation method is still being called.

beforeValidate: function(attrs, next) {
  // create a unique verification token
  // see https://github.com/broofa/node-uuid
  sails.log.debug("beforeValidate was called");
  if (!attrs.verificationToken) {
    var uuid = require('node-uuid');
    attrs.verificationToken = uuid.v4();
  }
  return next();
},

beforeValidation: function(attrs, next) {
  sails.log.debug("beforeValidation was called");
  return next();
},

> debug: beforeValidation was called

Posted to the Sails list and heading out to dinner.

@lucj
Copy link

lucj commented Jun 29, 2014

Ho Guy !!!! I was looking at the way to update my sails 0.9.16 app to 0.10 and all you went through is kind of scary. Seems like I'd better create a blank 0.10 sails project and copy my models / configs / controllers / ... from my 0.9.16 project. I think I'll not make the move now.

@Studira
Copy link

Studira commented Oct 4, 2014

Had the exact same issues and errors, its kind of scary to think you have to go through this with every major upgrade, let me wonder if sails is the right way for me to go?

@Vadorequest
Copy link

I updated one of my application yesterday, took me 3 hours (a lot of specific grunt stuff). I didn't encounter anything like your npm/node issues, on windows x64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment