0

Please speak slowly and clearly and use simple words-- I have no previous experience with node.js, sails.js, ejs, or grunt. I come from a PHP background.

We are developing a website based on sails.js and ejs. When we enable layouts in config/views.js, we get a lot of errors in the browser console. The first looks like this in Firefox:

ReferenceError: module is not defined
module.exports = function (grunt) {

...and like this in Safari:

ReferenceError: Can't find variable: module
global codeGruntfile.js:14

However, grunt seems to be working, at least in part: LESS are compiling OK, and the layouts are working. If we disable layouts (set "layout:false" in config/views.js and re-lift sails), the errors disappear, but then LESS and the layouts don't work.

I can work around not having the layouts with includes, but I'd really like to use LESS if at all possible. Anyways, I'd just like to use this framework the way it was intended to be used.

Sorry, it's also my first question here (as lurking has been enough for years), and I probably haven't posted enough technical information. Here is everything that the Safari console window spits at me when Sails is enabled (though I expect most of the errors down the page stem from a single config error). Let me know if I can provide any more information.

Thanks, eh.

[Error] ReferenceError: Can't find variable: module (Gruntfile.js, line 14)
[Error] ReferenceError: Can't find variable: angular
    (anonymous function) (app.js, line 21)
[Error] TypeError: 'undefined' is not an object (evaluating '$.ajaxSetup') (jquery.postmessage-transport.js, line 50)
[Error] ReferenceError: Can't find variable: angular (jquery.fileupload-angular.js, line 33)
[Error] TypeError: 'undefined' is not an object (evaluating '$.blueimp') (jquery.fileupload-audio.js, line 35)
[Error] TypeError: 'undefined' is not an object (evaluating '$.blueimp')
    (anonymous function) (jquery.fileupload-image.js, line 39)
    (anonymous function) (jquery.fileupload-image.js, line 30)
[Error] TypeError: 'undefined' is not an object (evaluating '$.widget') (jquery.fileupload-jquery-ui.js, line 27)
[Error] TypeError: 'undefined' is not an object (evaluating '$.blueimp') (jquery.fileupload-process.js, line 32)
[Error] TypeError: 'undefined' is not an object (evaluating '$.blueimp') (jquery.fileupload-ui.js, line 37)
[Error] TypeError: 'undefined' is not an object (evaluating '$.blueimp') (jquery.fileupload-validate.js, line 32)
[Error] TypeError: 'undefined' is not an object (evaluating '$.blueimp') (jquery.fileupload-video.js, line 35)
[Error] TypeError: 'undefined' is not an object (evaluating '$.support') (jquery.fileupload.js, line 32)
[Error] TypeError: 'undefined' is not an object (evaluating '$.ajaxTransport')
    (anonymous function) (jquery.iframe-transport.js, line 39)
    (anonymous function) (jquery.iframe-transport.js, line 21)
[Error] ReferenceError: Can't find variable: $ (main.js, line 14)
[Error] ReferenceError: Can't find variable: jQuery (jquery.ui.widget.js, line 18)
[Error] SyntaxError: Invalid character: '#' (server.js, line 1)
[Error] ReferenceError: Can't find variable: $ (test.js, line 14)
[Error] ReferenceError: Can't find variable: jwplayer (jwplayer.html5.js, line 1)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (jquery-1.10.2.min.map, line 0)
[Log] 
    |>    
  \___/  
[Log]  `io.socket` connected successfully.
 (for help, see: http://sailsjs.org/#!documentation/reference/BrowserSDK/BrowserSDK.html)

edit: running "npm cache clear" and "npm install" as suggested in the comments resulted in this:

npm WARN package.json crypto@0.0.3 crypto is also the name of a node core module.
npm WARN unmet dependency /home/ubuntu/git/(obscured)/frontend/node_modules/sails-disk/node_modules/waterline-criteria requires lodash@'~2.4.1' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined
npm WARN unmet dependency /home/ubuntu/git/(obscured)/frontend/node_modules/sails-disk/node_modules/waterline-cursor requires lodash@'~2.4.1' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined

additional edit 2014/09/15:

@KevinKao - Yes, we're on Ubuntu. I ran aptitude and it warned of the following dependency issues, and gave me an option to downgrade nodejs (from 0.10.31 to 0.10.25), but no option to downgrade npm.

The following packages have unmet dependencies:
nodejs : Conflicts: npm but 1.3.10~dfsg-1 is to be installed.

The following actions will resolve these dependencies:

Install the following packages:

1)     nodejs-dev [0.10.25~dfsg2-2ubuntu1 (trusty)]                             

Downgrade the following packages:  

2)     nodejs [0.10.31-1chl1~trusty1 (now, trusty) -> 0.10.25~dfsg2-2ubuntu1 (tr //oops truncated it

I ran 'aptitude install npm' again just for fun and didn't get any warnings, but when I ran 'npm install' I got the following warnings:

npm WARN deprecated grunt-lib-contrib@0.7.1: DEPRECATED. See readme: https://github.com/gruntjs/grunt-lib-contrib
npm WARN deprecated guid@0.0.12: Please use node-uuid instead. It is much better.

I went ahead and finished your procedure anyways, but got the same browser console errors that I was getting at the outset.

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
jasper
  • 137
  • 1
  • 9
  • Try running ````npm cache clear```` and ````npm install```` in your app's directory to install all dependencies again and see if the error still occurs. – kk415kk Sep 11 '14 at 06:36
  • Thanks Kevin, I tried that and got some messages about some missing dependencies. The browser console still gives the same error messages. – jasper Sep 11 '14 at 08:08
  • What version of Node.js, npm, and Sails.js are you using (to try to reproduce the problem)? I'm using Node.js (0.10.25), npm (1.3.10), and Sails.js (0.10.5) with layouts without any problems. You can get the versions by running ````nodejs -v````, ````sails -v````, and ````npm -v````. – kk415kk Sep 11 '14 at 08:42
  • Thanks for sticking with this Kevin! I'm using Node.js v.0.10.30, sails 0.10.4, and npm 1.4.21. I guess we try and upgrade sails then? – jasper Sep 11 '14 at 09:02
  • I actually had a problem with Sails/Node when running with npm 1.4.x. Try running ````sudo aptitude install npm```` and see if it gives you an option to downgrade (if you don't have aptitude, you can get it with ````sudo apt-get install aptitude````). I'm assuming you're running Ubuntu. Once you downgrade npm, do ````sudo apt-get install nodejs```` and ````npm install -g sails```` - then go to your app's folder, clear out the ````node_modules```` folder, and run ````npm install````. Hopefully this clears up any dependency issues. – kk415kk Sep 11 '14 at 09:12
  • Seems like something is seriously amiss with your project setup if you're seeing these errors in your *browser* console. It looks like it's trying to load **Gruntfile.js** in the front-end--perhaps in a ` – sgress454 Sep 12 '14 at 00:29
  • @KevinKao : Thanks again for sticking with this! Results of your latest suggestion posted above. I'm tempted to just reinstall everything from Ubuntu on up.... :( – jasper Sep 15 '14 at 01:24
  • @sgress454 : BOOM! NAILED IT! My coworker had moved a whole folder full of stuff to assets/js. I just moved it out of assets and the errors disappeared. Thanks for pointing in the direction of where to look! – jasper Sep 15 '14 at 07:54

1 Answers1

1

My coworker had moved a whole folder full of stuff to assets/js. I just moved it out of assets and the errors disappeared. Layout.ejs includes everything in this folder; hence the problems.

jasper
  • 137
  • 1
  • 9