Open iliyan-trifonov opened 9 years ago
Thanks for submitting this issue. I cover karma installation issues later in the book and thought I had updated everywhere earlier that required a specific karma version.
I'm glad you're enjoying the book. Hopefully there aren't too many other problems like these after the karma installation.
After the commands above I run grunt
with no problems and all tests pass. There was one little warning saying a deprecated something in a core module (sorry I didn't write down this one to give it here) and I installed node js 0.10.2
just in case and to be compatible with the next code in the book.
I also tried just to see what happens putting * in the place of the versions in package.json and installing. Everything installed successfully but the jshint test produced errors like "ES5 something is added automatically" and complaining I don't have "use strict" on places where I have it. So I decided to stick with the proper versions from the book. But that was just for testing and learning more about node and npm.
I remember another small thing that I had to take care of: I installed the latest version of express
and because express is now separated from some of its modules, I had to install express-generator
to be able to generate new apps with it and also on the facebook login app there was a need to install 2 other packages: cookie-parser
and cookie-session
and write:
var cookieParser = require('cookie-parser');
var session = require('cookie-session');
...
app.use(cookieParser());
app.use(session({secret: 'SECRET'}));
in the place of:
app.use(express.cookieParser());
app.use(express.session({secret: 'SECRET'}));
I think the express generator already provided app.use(cookieParser());
but I remember I still had to install cookie-parser
with npm
.
I will lower the globally installed express version if I reach a problem with it so it's not a big deal.
And the other thing is about mocha
/assert.equal
that didn't show actual/expected on fail, only the message I provided and a stack trace but when the message is removed it shows the compared values.
For this one I think I just have to get used to the system to be able to do what I need.
As a whole these things are nothing that can't be solved after a 5min Google search but I wanted to be exhaustive in my reply here :)
I don't believe there will be heart breaking probs from now on and it will be fun for me to check what changed between the versions of the tools.
Keep up the good work!
It sounds like you're doing everything right (trying out the tools, that is).
The issue you had with jshint complaining about ES5 syntax can be fixed by removing the es5: true
setting from the config. However, I haven't seen jshint complain about 'use strict';
when one already exists. I may checkout an earlier version of the code and follow your same steps to see what may have caused it. Or, if you're working in a repo could you link me to what you've changed?
I have experienced the same thing with mocha, and I believe an update of mocha fixed the problem. Either that or I switched to using chai.js's assert over the node API's assert.
One thing to be careful of with your update of express.js is that Express 3 and Express 4 may have different APIs or breaking changes that may have been used in the sample code. Check out the migration docs so you're aware of those changes if you see them in the code.
Here's an interesting anecdote about open source version upgrades that I don't remember putting in the book. My previous position was at Expedia, where my team was creating a CMS for internal use. It was written in Scala with AngularJS and ui.bootstrap on the frontend. At one point, someone decided to upgrade from ui.bootstrap 0.9.0 to ui.bootstrap 0.11.0. We were using Bootstrap 2.3.x and whoever did this seemingly harmless upgrade didn't check the documentation for 0.11.0 (which is somewhat hidden):
This version of the library (0.11.0) works only with Bootstrap CSS in version 3.x. 0.8.0 is the last version of this library that supports Bootstrap CSS in version 2.3.x.
We ended up having to update Bootstrap to 3.0. It wasn't a huge deal, but it took something like two days when we thought the original task would only take an hour or so.
First I want to make one correction of the node version I picked in my last comment:
I said before that I installed the older version of node: 0.10.2.
But then I decided to repeat the process with karma and this time I received too many new errors with other packages. Things like dir not empty, file cannot be overwritten and others. I think this is because newer versions of other packages are made for newer node/npm versions.
So I went back to 0.10.29 and everything is working well now like before. I tried with the latest 0.12.0 and it's working too - I will stick with this version for now. There are some light warnings coming from the packages' json configs with the latest node like: "need node 0.8 - 0.10" but everything is working so I don't mind it. Of course the karma fix from my first post is needed.
I am using nodejs/mongodb under Win8 64bit as my laptop and tablet came with it and I paid for the thing but at the office(and my dedicated server) I am an Ubuntu guy and I also use a lot Vagrant and VirtualBox at home. I will install Ubuntu at home in the next months. My point is that for now node behaves very well under Windows so I think there are no problems with the packages because of that.
Don't bother much with my tests in package.json as I am forcing all new versions in my post above just for fun.
However I've made a repo on my GitLab which can be cloned (https://gitlab.iliyan-trifonov.com/node-js/yfa-node-test-versions.git) and then run npm install. I've updated some of the dev deps with their latest working versions. It should install everything successfully and then run grunt.
I left the jshint package at its original version.
For the errors run npm install grunt-contrib-jshint
for the latest version and then the jshint errors come:
$ grunt
Running "env:test" (env) task
Running "jshint:app" (jshint) task
src\app.js
>> ES5 option is now set per default
src\public\javascripts\app.js
>> ES5 option is now set per default
src\public\javascripts\controllers.js
>> ES5 option is now set per default
38 |};
^ Missing "use strict" statement.
46 |};
^ Missing "use strict" statement.
65 |};
^ Missing "use strict" statement.
75 |};
^ Missing "use strict" statement.
src\public\javascripts\directives.js
>> ES5 option is now set per default
1 |/*jshint unused:false */
^ ES5 option is now set per default
src\public\javascripts\filters.js
>> ES5 option is now set per default
src\public\javascripts\main.js
>> ES5 option is now set per default
src\public\javascripts\services.js
>> ES5 option is now set per default
src\routes\index.js
>> ES5 option is now set per default
src\routes\resource.js
>> ES5 option is now set per default
>> 14 errors in 9 files
Warning: Task "jshint:app" failed. Use --force to continue.
Aborted due to warnings.
I've set "es5": false
and its warnings are gone.
The ones with src\public\javascripts\controllers.js
are still there.
I also tried grunt --force
but there are other incompatibilities in the following tasks so I decided to update the packages one by one.
For now only the jshint warnings are there.
I've found that I can check local package versions with npm list | grep grunt-contrib-jshint
(or without | grep
) and then install the latest with npm install grunt-contrib-jshint
, etc.
I've also found that with es5: false
the older jshint version complains.
I wanted to congratulate you with the choice of an IDE(WebStorm). I personally use PHPStorm since 2 years and I am very happy with it. It's working with node/angular too. I also was celebrating when I heard that the new Android studio is using IDEA :)
And the story with Bootstrap3 reminded me of my own troubles when I started with Bootstrap2 and then version 3 came. The same happens with Laravel 4->5 now but I will put JavaScript on prio until I am able to do my own MEAN stack sites.
That's it for now. I better go back to the book and continue with the next chapters :)
One more thing about the mongoose
local package.
I've discovered that the required version 1.3.19
is removed from the npm registry.
Then I've tried installing with mongoose@1
which gave me version 1.8.4
but this time it was my bad - that version said it doesn't support Windows.
So I've installed successfully with mongoose@1.3
which gave me 1.3.7
. I'll have to finish the chapter later to be sure that this version is ok.
If not I think there was a way to find and install 1.3.19 manually
.
I'll be putting here other packages(if any) that I had troubles with(and solutions).
I just tried all things we discussed here under Ubuntu 14.04 with node 0.12.0 installed with nvm and everything behaves the same as my original tests under Win8. The only difference: under Linux tests are running way faster.
I've noticed that tests run faster under Linux also. I recently switched to OS X, and tests seem to run more quickly on my Macbook Pro 2.4 GHz Intel Core i5 (8GB RAM) than they did on my previous machine, a System76 Pangolin Performance 2.30GHz Intel Core i7 (16GB RAM).
I'm wondering if any issues you've been having with the different versions of node could be related to nvm. I don't want to knock Tim Caswell because I think he's awesome and he's contributed a lot to the community, but I've never had a great experience with nvm (or with n). It's been a while, but I believe most of my issues were related to permissions when installing modules.
I now prefer nave, which is written and maintained by the same guy that wrote and maintains npm and npmjs.org. I'm not sure if nvm and nave can run side by side, but if you have a lot of problems that sound like permissions (directory not empty, cannot overwrite, etc.) I'd try nave.
If you're still getting errors about a missing 'use strict';
in controllers.js, you can add the line to the top of the file and it should resolve any problems. I may have missed a few things early on in the book. Tests should at least run successfully at the end of each chapter.
If you're using WebStorm, you can also configure it to use the .jshintrc and report issues or suggestions within the editor. The quickest way to find the setting is to open WebStorm's preferences and search for jshint:
The npm command line tool is pretty powerful and it takes some getting used to. Check out the documentation for npm view. You can quickly get a list of versions for jshint, for example, with:
npm view jshint versions
…where versions
is the key of the response object you want to look at. If you just use npm view jshint
, it will dump all information about the package. If you want to dump that information to a parseable JSON, you can do npm view jshint --json
.
If you install underscore-cli, you can process JSON directly from the command line. If you're familiar with underscore, this would be very useful. If you're not familiar with underscore, it doesn't hurt to get familiar with it since it enables functional programming with JavaScript. To get the most recent version of an npm module:
npm view jshint --json | underscore process '_.last(data.versions)'
Then, you can install the specific version: npm install jshint@2.6.0 --save-dev
. I'm sure you could play around with it and work out some alias to do this automatically. You could also use the underscore cli to figure out more information about dependencies and whatnot.
I'll check out your linked repo tonight or tomorrow. Thanks for sharing it.
Thank you for guiding me through the process! I've learned a lot reading the book so far and following your advice here.
I continue with the book. I take my time to write the code, test it, check if there is an error, rest, look on the net to get used to for example mocha and mongoose today. I am also checking the tools you provided here like underscore and chai.
I am feeling more confident every day and I am writing down any extra changes I make. I am going to paste the final result here after I am ready with the book.
I wanted to give you my other link where I commit step by step the code from the book: https://gitlab.iliyan-trifonov.com/node-js/yfa-node . It's completely working so far and includes the local karma version setting from my first comment above. I am updating it a little every day and my progress can be checked there.
It took me a little longer to check out your fork than I thought it would. I received an email about a prior obligation for a book review and I had to complete it on a short deadline.
I tried your fork under node 0.10.20, 0.11.9, and 0.12.0 and I couldn't reproduce the jshint problem. It's possible that some dependency wasn't properly updated while switching between different versions of node. I'm using jshint 2.3.0.
To be safe, you can remove the local node_modules
directory any time you want to try a different version of node. I did see the karma issues.
I know there's also a problem with older versions of npm when you install packages from current revisions. It has something to do with semantic versioning patterns that are supported in the newer versions of npm. I don't think it's an issue if you're running npm 2.x, but if you're running 1.3.x or 1.4.x, you may have problems pulling newer versions of packages. You can, interestingly, upgrade npm using npm:
npm install -g npm
I don't recall how the -g
switch works in nvm, but in nave, it will install globally to ~/.nave/installed/0.10.20/lib/node_modules/npm
. The current version of npm is 2.5.1.
Thank you for checking my repo. Sorry. I decided to stick with the older version of grunt-contrib-jshint while working with the book for some time to not cause extra work outside the scope of it.
But I've got some experience already and after you told me what to do in the previous comments I decided to do it now. I also scrolled the book to the bottom to see if I will install additional packages in the near future and I think only the socket.io package will be needed but from this point since I managed to work with the karma packages I have only successes and I don't have problems.
I've just put the jshint upgrade changes on the repo and they can be seen here https://gitlab.iliyan-trifonov.com/node-js/yfa-node/commit/1ce329a1bcabb26a96734b6c67efb9d63efb9974 This is the working version. I've also removed the other "use strict" in controllers.js after putting it on the top of the file after jshint warned me and now the test is clean :)
I want to write some stuff I've done so far later here. Most of it is just interesting things I discover and maybe 1-2 things connected to the project. I'll compile a small list later today and put it here.
Hello, I will put here my settings and things that others may find interesting.
I want to tell that I am following the code in the book 1:1 and also keeping the yfa-node repo on GitHub(pure gold!) open in one tab - it helps me finding where a new file is situated when I am still not sure or when I am stuck with the things that I have to do by myself(homework) :)
I am on the API chapter(node) and still have a long way to walk. But I already don't have problems and we should consider closing this issue.
My current configuration is:
Ubuntu 14.04.2 LTS 64bit
node v0.10.36
npm 1.4.28
current modules in the project
$ npm ls --dept 0
yfa-nodejs@0.1.0 /home/iliyan/WORK/nodejs/yfa-node
├── async@0.2.10
├── ejs@2.2.4
├── express@3.2.6
├── grunt@0.4.5
├── grunt-contrib-jshint@0.11.0
├── grunt-contrib-nodeunit@0.1.2
├── grunt-contrib-watch@0.2.0
├── grunt-env@0.4.2
├── grunt-express@1.0.1
├── grunt-karma@0.6.2
├── grunt-mocha-istanbul@2.3.1
├── http-status@0.1.8
├── istanbul@0.3.5
├── jade@1.9.2
├── jasmine-node@1.10.2
├── karma@0.10.10
├── karma-chai@0.0.1
├── karma-chrome-launcher@0.1.7
├── karma-coffee-preprocessor@0.1.3
├── karma-coverage@0.1.5
├── karma-firefox-launcher@0.1.4
├── karma-html2js-preprocessor@0.1.0
├── karma-jasmine@0.1.5
├── karma-mocha@0.1.0
├── karma-ng-scenario@0.1.0
├── karma-phantomjs-launcher@0.1.4
├── karma-requirejs@0.2.2
├── karma-script-launcher@0.1.0
├── mocha@1.12.1
├── mongoose@3.8.23
├── passport@0.2.1
├── passport-facebook@1.0.3
├── requirejs@2.1.16
└── should@5.0.0
My node is installed with(apt):
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
Install mongodb
: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
build-essential
is needed for some npm
modules to build their stuff.
Interesting things I've found while checking different node
, npm
, nave
and modules versions:
1.3.7
which I tried is too old even compared to the needed 1.3.19
.
With that version the third param in mongoose
model save is undefined.
Other 1.* versions have probs with the tests freezing.
Corrected by installing a newer version of mongoose
like the latest one: 3.8.23
(See package.json
and the versions above).The local karma-mocha
version may be fixed in package.json
instead of installing it separately:
So the first fix will become:
npm install -g karma-coffee-preprocessor@0.1.3 npm install -g karma@0.10.4 jshint@2.3.0 ###deprecated: npm install karma-mocha@0.1.0 ###set "karma-mocha": "0.1.0" in package.json instead npm install -d
Install express
globally using version 3.
This will make it compatible with the code in the beginning of the book:
no need to install express-generator
, cookie-session
and cookie-parser
and changing the code in app.js
,
just following the book's code will be enough.
Let's use the same version as in package.json
:
npm install -g express@3.2.6
Deauthorize from your FB app to test the login/credentials approving again. I've found that we can deauthorize a user of our app by calling:
curl -X DELETE "https://graph.facebook.com/PROFILE_ID/permissions?access_token=ACCESS_TOKEN"
I haven't tested it yet but I thing the required information id/token is already given to us and we can use that for a fresh start. Or we can create a new FB app and use its new id/secret.
Rebuild all local modules.
May be needed when w are switching between node
/npm
versions(e.g. with nave use 'version')
or a module like mongoose
warns us that its c++ stuff
is not found and will use pure js
implementation(slower module) - this may need build-essential
installed first.
rm -rf node_modules
npm cache clean
npm install
Of course this one may also do the job:
npm uninstall 'package'
npm install 'package'
###add -g for global installs
recursive:true
option to mocha_istanbul
in Gruntfile.js
.
I have a subdir in test/server
: models/
that was not used by mocha
and fixed it with the recursive option.
Another way is to add additional dirs in the src: [array]
.
The recursive behaviour probably is different between different module versions.Yahoo REST link error. I find this important as it's directly connected to the book.
http://developer.yahoo.com/social/rest_api_guide/http-response-codes.html
The page loads slow and at the end gives: "An internal error occurred (eid xxxxxxxx)."
.
However the web archive version works :)
Update: The original link loads normally today, after a couple of refreshes. Seems like a server overload.
I've added some global variables to .jshintrc and the final result is:
"predef": "additional predefined global variables", "predef": ["angular","describe","it","before","after","beforeEach"]
Now jshint will be happy :)
I've added .git/hooks/pre-commit
to make some of the grunt tests
run on commit.
Currently it only runs jshint
and helps me correct something in the syntax that I've forgot.
echo "grunt jshint" > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
I've also found that there are npm
/grunt
modules that handle the hooks for us but this will be checked in the future.
With all this I consider my problems with the modules are solved.
Thank you! :)
First thank you for the good book! :)
I've reached the place in the book where we install karma and jshint globally and also install the skeleton yfa project's dependencies.
I've received dependency errors and started debugging.
The errors provided a very good information about what dependency needs a newer version than the one we provide in
karma@...
Using my experience with the PHP's composer I realised that karma's package at this specific version is looking for the latest version of one of its dependencies.
I also knew that if I install this dependency before karma, it will be used instead of the latest one. The same thing happened with the local yfa packages.
I just picked older versions of the dependencies without researching them thoroughly by only checking with
npm show 'package' versions
These are the commands I used. Maybe there is a better way but I leave them here as a reference to other people like me if they happen to have the same problem:
I'm planning later to modify a little package.json to have this automatically for the local packages.