I'm a bit stuck with my Jenkins setup on OSX Lion 10.7.3.
I'm using Grunt in my webapp to run Jasmine tests, build less, create cache manifest etc. Everything works on my laptop Lion 10.7.5, but on the server box grunt fails from time to time with the following error:
$ grunt less
module.js:340
throw err;
^
Error: Cannot find module ''
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at ChildProcess.<anonymous> (/usr/local/lib/node_modules/grunt-cli/bin/grunt:44:3)
at ChildProcess.EventEmitter.emit (events.js:99:17)
at Process._handle.onexit (child_process.js:678:10)
This is intermittent, it fails approximately once out of five runs and is not task specific. It fails with the same rate when running grunt manifest or grunt test.
Once thing I noticed is that when it works it takes a second or two until the task starts executing, but when it fails it fails immediately.
I tried to remove node_modules, npm cache clear, reinstalling grunt-cli. Nothing works.
Here's my package.json:
{
"name": "webapp",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "0.4.0rc7",
"grunt-contrib-copy": "0.4.0rc7",
"grunt-contrib-concat": "0.1.2rc6",
"grunt-contrib-coffee": "0.4.0rc7",
"grunt-contrib-uglify": "0.1.1rc6",
"grunt-contrib-compass": "0.1.1rc8",
"grunt-contrib-jshint": "0.1.1rc6",
"grunt-contrib-mincss": "0.4.0rc7",
"grunt-contrib-connect": "0.1.1rc6",
"grunt-contrib-clean": "0.4.0rc6",
"grunt-contrib-htmlmin": "0.1.1rc7",
"grunt-contrib-imagemin": "0.1.1rc8",
"grunt-contrib-livereload": "0.1.0rc8",
"grunt-contrib-jasmine": "~0.3.2",
"grunt-contrib-less": "0.5.0",
"grunt-manifest": "0.4.0",
"grunt-jslint": "0.2.5",
"grunt-bower-hooks": "~0.2.0",
"grunt-usemin": "~0.1.7",
"grunt-regarde": "~0.1.1",
"grunt-requirejs": "~0.3.1",
"grunt-mocha": "~0.2.2",
"grunt-open": "~0.1.0",
"matchdep": "~0.1.1"
},
"engines": {
"node": ">=0.8.0"
}
}
npm and node versions:
$ npm -version
1.2.11
$ node --version
v0.8.20
I have now stripped down both packages.json and Gruntile.js:
$ cat package.json
{
"name": "webapp",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "0.4.0rc7",
"grunt-manifest": "0.4.0",
"matchdep": "~0.1.1"
},
"engines": {
"node": ">=0.8.0"
}
}
$ cat Gruntfile.js
'use strict';
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
manifest: {
generate: {
options: {
basePath: 'app/',
exclude: ['js/lib/amp/com.vaultus.api.WebApiAggregated.cache.js', 'js/lib/amp/com.vaultus.api.DebugWebApiAggregated.cache.js'],
timestamp: true
},
src: [
'index-hybrid.html',
'*.xml',
'js/**/*.js',
'css/**/*.css',
'css/images/**/*',
'i18n/**/*.js',
'template/**/*.html'
],
dest: 'app/cache-manifest.mf'
}
}
});
grunt.registerTask('build', [
'manifest'
]);
grunt.registerTask('default', ['build']);
};
No luck :(
We were hitting this issue on our CI builds.
After a bit of digging it looks like this was a bug in grunt-cli 0.1.6 and has been fixed in 0.1.7 of grunt-cli.
Related
i have created a ne node project, i have installed a lot of modules and create the first index.js file
package.json
{
"name": "parser-test",
"version": "1.0.0",
"description": "parser test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "luca bottoni",
"license": "ISC",
"dependencies": {
"node-cmd": "^3.0.0"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-exec": "^3.0.0"
}
}
index.js (it's failed, because i want see jshint message!)
console.log("test");
a={a=6};
if i send the cmd jshint index.js from project folder i see (work fine):
index.js: line 3, col 5, Expected ':' and instead saw '='.
1 error
now i want use the grunt task to check my file
Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch:{
scripts:{
files:["./*.js"],
tasks:['jshint']
}
},
jshint: {
files: ['Gruntfile.js',"index.js"]
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Default task(s).
grunt.registerTask('default', ['watch:scripts']);
grunt.registerTask('jshint', ['jshint']);
};
now i try use single task jshint with command grunt jshint, but the don't see any message. if i use the watch, watch task only the first time and after not check any change on file index.js.
i can not understand why the direct command jshint work, but the task grunt stay freezed
i have resolved after many test
i have turn-on verbose information on grunt command
grunt jshint --verbose and i have see infinite:
Running "jshint" task
Running "jshint" task
Running "jshint" task
Running "jshint" task
Running "jshint" task
Running "jshint" task
The register task and task in definition have the same name "jshint" and i have modified the name in grunt.registerTask('jshints', ['jshint']);
now work fine
I'm just getting started with Phoenix and Elixir, and am coming to a hurdle at the very start with my scss/css files.
Following some blogs/articles, I have done the following so far:
renamed app.css to app.scss
Created new dir '_scss' where I am putthing my scss files.
In app.scss I am importing my scss files.
#import "../_scss/_foundation.scss";
package.json looks like:
{
"repository": {},
"license": "MIT",
"scripts": {
"deploy": "brunch build --production",
"watch": "brunch watch --stdin"
},
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"bourbon": "^4.3.4",
"bourbon-neat": "^2.0.0",
"foundation-sites": "^6.3.1",
"phoenix": "file:deps/phoenix",
"phoenix_html": "file:deps/phoenix_html",
"purecss": "^0.6.2",
"sass-brunch": "^2.10.4"
},
"devDependencies": {
"babel-brunch": "~6.0.0",
"brunch": "2.7.4",
"clean-css-brunch": "~2.0.0",
"css-brunch": "~2.0.0",
"javascript-brunch": "~2.0.0",
"uglify-js-brunch": "~2.0.1"
}
}
And in brunch.config.js I have:
stylesheets: {
joinTo: "css/app.scss",
order: {
after: ["web/static/css/app.scss"] // concat app.css last
}
},
I changed the above to reflect the name change of app.scss. Was that correct?
And when I load the server, the page loads, but without any styling. My terminal just seems to be constantly compiling...
24 Apr 15:01:56 - info: compiling..
What am I doing wrong here?
UPDATE
Seems to be the individual file. Int his case foundation.scss. I just tried another framework , Bulma, and it worked instantly.
I upgraded my Elixir version from 3.0 to 5.0. The npm update command runs fine but when I try to run gulp --production it fails.
I have given the error below which I get.
My package.json file (which should be identical to the one at https://github.com/laravel/laravel/blob/master/package.json)
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^5.0.0",
"bootstrap-sass": "^3.3.0"
}
}
When running gulp --production I get the below error
/home/vagrant/Code/laravel/node_modules/laravel- elixir/node_modules/gulp- cssnano/node_modules/cssnano/node_modules/postcss/lib/lazy-result.js:157
this.processing = new Promise(function (resolve, reject) {
^
ReferenceError: Promise is not defined
at LazyResult.async (/home/vagrant/Code/laravel/node_modules/laravel-elixir/node_modules/gulp-cssnano/node_modules/cssnano/node_modules/postcss/lib/lazy-result.js:157:31)
at LazyResult.then (/home/vagrant/Code/laravel/node_modules/laravel-elixir/node_modules/gulp-cssnano/node_modules/cssnano/node_modules/postcss/lib/lazy-result.js:79:21)
at Transform.stream._transform (/home/vagrant/Code/laravel/node_modules/laravel-elixir/node_modules/gulp-cssnano/index.js:27:17)
at Transform._read (_stream_transform.js:179:10)
at Transform._write (_stream_transform.js:167:12)
at doWrite (_stream_writable.js:226:10)
at writeOrBuffer (_stream_writable.js:216:5)
at Transform.Writable.write (_stream_writable.js:183:11)
at write (/home/vagrant/Code/laravel/node_modules/laravel-elixir/node_modules/gulp-concat/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
at flow (/home/vagrant/Code/laravel/node_modules/laravel-elixir/node_modules/gulp-concat/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
You need to upgrade Node also.
You can read here how it can be updated upgraded: https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version
I am using karma & jasmine to do unit tests, and I am trying to do my first test. I am using the first example here:
https://jasmine.github.io/1.3/introduction.html#section-Matchers
and it didn't seem to do anything, so I added some logging and tried to make it catch an error:
console.log('a');
describe("A suite", function() {
console.log('b', typeof(it));
it("contains spec with an expectation", function() {
console.log('c');
expect(true).toBe(false);
});
});
And this is what my output comes out with:
Chrome 43.0.2357 (Mac OS X 10.10.3) LOG: 'a'
Chrome 43.0.2357 (Mac OS X 10.10.3) LOG: 'b', 'function'
so it looks like nothing internal to the "it" function gets executed since 'c' is never outputted. Am I missing something?
Update
So this is the grunt task I am running:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
karma: {
unit: {
configFile: 'karma.conf.js'
}
}
});
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('default', ['karma']);
};
And this is my package.json with the list of installed npm packages:
{
"name": "abc.com",
"version": "0.0.1",
"private": true,
"dependencies": {
"bcrypt": "^0.8.3",
"body-parser": "^1.0.2",
"bower": "^1.4.1",
"ejs": "^2.3.1",
"email-templates": "^2.0.0-beta.1",
"error-handler": "^0.1.4",
"errorhandler": "^1.3.6",
"express": "~4.1.1",
"express-session": "^1.11.2",
"grunt": "^0.4.5",
"jade": "~0.31.2",
"jasmine": "^2.3.1",
"jasmine-runner": "^0.2.9",
"karma": "^0.12.37",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.5",
"karma-junit-reporter": "^0.2.2",
"method-override": "^1.0.0",
"morgan": "^1.0.0",
"mysql": "^2.6.2",
"nodemailer": "^1.3.4",
"protractor": "^1.1.1",
"shelljs": "^0.2.6",
"xoauth2": "^1.0.0"
},
"scripts": {
"prestart": "npm install",
"postinstall": "bower install --allow-root",
"start": "supervisor -n error app.js",
"pretest": "npm install",
"test": "karma start karma.conf.js",
"test-single-run": "karma start karma.conf.js --single-run",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
"preprotractor": "npm run update-webdriver",
"protractor": "protractor e2e-tests/protractor.conf.js",
"update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/##NG_LOADER_START##[\\s\\S]*\\/\\/##NG_LOADER_END##/, '//##NG_LOADER_START##\\n' + sed(/sourceMappingURL=angular-loader.min.js.map/,'sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map','app/bower_components/angular-loader/angular-loader.min.js') + '\\n//##NG_LOADER_END##', 'app/index-async.html');\""
},
"configs": {
"client_javascript_paths": [
"public/components/common/helpers.js",
"public/libs/bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js",
"public/libs/bower_components/jquery/dist/jquery.min.js",
"public/libs/bower_components/angular/angular.js",
"public/libs/bower_components/angular-route/angular-route.js",
"public/libs/bower_components/angular-resource/angular-resource.js",
"public/libs/bower_components/d3/d3.js",
"public/libs/bower_components/c3/c3.js",
"public/libs/bower_components/angular-chart/angular-chart.js",
"public/libs/bower_components/moment/moment.js",
"public/components/common/filters.js",
"public/components/notify/notify.js",
"public/components/static/static.js",
"public/components/account/account.js",
"public/components/auth/auth.js",
"public/components/formatted-table/formatted-table.js",
"public/app.js",
"public/libs/underscore.js"
]
},
"devDependencies": {
"jasmine": "^2.3.1",
"jasmine-core": "^2.3.4",
"karma": "^0.12.37",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.2.0",
"phantomjs": "^1.9.17"
}
}
And finally, this is my karma.conf.js
module.exports = function(config) {
var package = require('./package.json')
console.log(package.configs.client_javascript_paths);
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],
// list of files / patterns to load in the browser
files: package.configs.client_javascript_paths.concat([
'public/components/**/*.tests.js'
]),
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
and I just run
grunt
to start it to get the output at the top of this.
It is happening because of requirejs framework you use with karma. If you don't need it, then you could just remove it from karma.conf.js and test will work just fine. But if you actually need it, then I would suggest to look at this documentation page, explaining how to configure requirejs for karma, it actually requires an extra file.
Using the files you've presented in the question I was able to execute the tests after the following steps:
first create a backup of karma.conf.js
use CLI command karma init to reinitiate creation of karma config
on the step Do you want to use Require.js ? selected Yes
on the step Do you wanna generate a bootstrap file for RequireJS? selected Yes
copied everything from a backup and added a file that was generated by karma init, it should be called test-main.js, to the list of watched files:
module.exports = function(config) {
var package = require('./package.json');
config.set({
// ...
files: package.configs.client_javascript_paths.concat([
'public/components/**/*.tests.js',
'test-main.js', // here it is
])
// ...
});
};
I have a cli app written in coffee-script. The cli app uses commander (https://github.com/tj/commander.js) to take arguments. I have three files in my bin dir:
mediatidy
mediatidy-config
mediatidy-media
If I run bin/mediatidy in the project folder in bash commander executes fine. If I type bin/mediatidy config or bin/mediatidy media in bash commander also executes fine and is waiting for an <action>.
The odd thing is I published the project to npm and get different results when installed globally. If I install the project via sudo npm mediatidy -g (I am using Mac OSX 10.10) I can see the following files in /usr/local/bin/:
mediatidy
mediatidy-config
mediatidy-media
If I run bin/mediatidy in the project folder in bash commander executes fine. If I type bin/mediatidy config or bin/mediatidy media in bash I get the following error:
mediatidy config
/usr/local/lib/node_modules/mediatidy/bin/mediatidy-config:3
program = require 'commander'
^^^^^^^^^^^
SyntaxError: Unexpected string
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Looks like a coffeescript compilation error... wat.
If I run the same command but with the dash, bin/mediatidy-config, it works fine. I have another app that is private that works without having to use the dash that is globally installed. What am I missing here?
edit: added my package.json file:
package.json:
{
"preferGlobal": true,
"main": "index",
"name": "mediatidy",
"description": "Keep your media nice and tidy!",
"version": "0.1.1",
"repository": {
"type": "git",
"url": "git#github.com:tkdan235/mediatidy.git"
},
"engines": {
"node": ">=0.10.0"
},
"directories": {
"bin": "bin",
"lib": "lib"
},
"dependencies": {
"async": "^0.9.0",
"coffee-script": "^1.8.0",
"colors": "^0.6.2",
"commander": "^2.1.0",
"fs-extra": "^0.11.1",
"lodash": "^2.4.1",
"nconf": "^0.7.1",
"node-dir": "^0.1.6",
"node-ffprobe": "^1.2.2",
"prompt": "^0.2.14",
"sqlite3": "^2.2.7"
},
"coffeelintConfig": {
"max_line_length": {
"name": "max_line_length",
"value": 120,
"level": "error",
"limitComments": true
}
}
}
This actually appears to be a limitation of Commander.js. At first glance, it doesn't appear to call the scripts as shell scripts. Instead, it calls them with node which won't be compiling the CoffeeScript code. See https://github.com/tj/commander.js/blob/master/index.js#L447-L479 (line 469 in particular).
Update:
After some further digging, it looks like this WAS once supported and working. The way sub-commands were called was just their script name. Then this pull request broke it: https://github.com/tj/commander.js/pull/173. The last working version for this behavior was in 2.1.0. You could pin your version to 2.1.0 to get this behavior back.