Grunt reference error - node.js

Gruntfile.js
module.exports = functions(grunt)
{
grunt.initConfig({
//pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';',
},
dist: {
src: ['APIdocu/AccountsCollection.md', 'APIdocu/AccountsFollowersCollection.md'],
dest: 'APIdocu/ConcatApis.md',
//files: {
//'APIdocu/NewApi.md' : ['APIdocu/AccountsCollection.md', 'APIdocu/AccountsFollowersCollection.md']
},
},
});
grunt.loadNpmTasks('grunt-contrib-concat');
//tasks
grunt.registerTask('default', ["concat"]);
}
error message
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Loading "Gruntfile.js" tasks...ERROR
ReferenceError: grunt is not defined
at Object.<anonymous> (C:\Users\gs1460\Desktop\Markdownfiles\apis\Gruntfile.js:1:90)
at Module._compile (module.js:456:26)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at loadTask (C:\Users\gs1460Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\task.js:323:10)
at Task.task.init (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\task.js:437:5)
at Object.grunt.tasks (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt.js:120:8)
at Object.module.exports [as cli] (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\cli.js:38:9)
Running tasks: concat:dist
Warning: Task "concat:dist" not found. Use --force to continue.
Aborted due to warnings.
How do I get rid of this error.
I need to concatenate md files to one.It gives me the above error. Tried changing the code many times. But same issue. Can you help in this.

Probably the problem is that you are writting functions instead of function.
Check also if the variable grunt is in the correct scope. And please use tabs correctly!
module.exports = function(grunt)
Regards.

Related

How to use a global nodejs module?

I got the following error when I try to use esprima. Does anybody know how to fix the problem? Thanks.
$ npm install -g esprima
/usr/local/bin/esparse -> /usr/local/lib/node_modules/esprima/bin/esparse.js
/usr/local/bin/esvalidate -> /usr/local/lib/node_modules/esprima/bin/esvalidate.js
+ esprima#4.0.1
updated 1 package in 0.837s
$ cat main.js
#!/usr/bin/env node
// vim: set noexpandtab tabstop=2:
var esprima = require('esprima');
var program = 'const answer = 42';
console.log(esprima.tokenize(program));
console.log(esprima.parseScript(program));
$ node main.js
internal/modules/cjs/loader.js:960
throw err;
^
Error: Cannot find module 'esprima'
Require stack:
- /private/tmp/main.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/private/tmp/main.js:4:15)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/private/tmp/main.js' ]
}
I think you installed esprima module in global node_modules.
If you want to use esprima in main.js which is located at /private/temp/main.js,
you should run npm install esprima in /private/temp/ without -g
EDIT - How to require global modules
Way 1
I assume you're in mac system.
Before you run your main.js, run export NODE_PATH=/usr/local/lib/node_modules in the shell, not node.js program.
Then you could require the global modules by const esprima = require("esprima").
By the way, global modules position could be different in the different system.
Way 2
After you knew your global modules position,
you could require it by const esprima = require("/usr/local/lib/node_modules/esprima")

The "amdefine" can not load a custom module

I installed the requirejs package to optimize the work with paths to files. In general, I do the next steps:
I have an object with paths to file, that have next values:
"app/database": "/home/dmitry/projects/information-platform-api/app/utils/database"
After I initialize the requirejs mapping in app.js (main file):
requirejs.config({
baseUrl: __dirname,
nodeRequire: require,
paths: paths,
map: {
'*': paths
}
});
After, I need to initialize base models, and with help for I called all files from paths object. This looks like:
for (let file in paths) {
requirejs(paths[file]);
}
When I initializing the file, which has the dependency of the above "app/database", I have a message error: Error: Cannot find module 'app/database'.
Maybe, I don't understand "How works the amdefine", but I have opinion, what a requirejs and amdefine don`t link. Do you have any ideas, why it doesn't work?
A part of the file, which need to investigate:
if (typeof define !== 'function') {
var define = require('amdefine')(module);
}
define([
'sequelize',
'app/database',
'model/student'
], (
Sequelize,
sequelize,
Student
) => { });
Result of my investigation:
The amdefine doesn't know about requirejs mapping.
Full error message:
Error: Tried loading "/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company" at /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company then tried node's require("/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company") and it failed with error: Error: Cannot find module 'app/database'
Require stack:
- /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js
- /home/dmitry/projects/information-platform-api/app.js
- /home/dmitry/projects/information-platform-api/bin/www
at /home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2600:27
at Object.execCb (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1946:33)
at Module.check (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1133:51)
at Module.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1426:22)
at Object.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1807:39)
at Function.req.get (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2524:33)
at Object.localRequire [as require] (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1678:40)
at requirejs (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2047:24)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/app.js:142:5)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/bin/www:7:13)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
originalError: Error: Cannot find module 'app/database'
Require stack:
- /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js
- /home/dmitry/projects/information-platform-api/app.js
- /home/dmitry/projects/information-platform-api/bin/www
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at req (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:144:31)
at stringRequire (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:220:28)
at amdRequire (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:113:24)
at /home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:177:24
at Array.map (<anonymous>)
at runFactory (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:176:25)
at define (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:277:13)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js:5:1)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at /home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2598:75
at Object.execCb (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1946:33)
at Module.check (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1133:51)
at Module.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1426:22)
at Object.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1807:39) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js',
'/home/dmitry/projects/information-platform-api/app.js',
'/home/dmitry/projects/information-platform-api/bin/www'
]
},
moduleName: '/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company',
requireModules: [
'/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company'
]
}
Process finished with exit code 1
The solution is here guys. The amdefine have two params, first param it's a global variable module, and the second it's require function for calling the local files. By default, it was just require not requirejs which contains custom mapping.
if (typeof define !== 'function') {
var define = require('amdefine')(module, require('requirejs'));
}

Found extra flags error in new version of protractor

I am trying to run a js scripts using protractor, but i am getting following error
C:\Users\Hoodi\AppData\Roaming\npm\node_modules\protractor\built\cli.js:172
throw new Error('Found extra flags: ' + unknownKeys.join(', '));
^
Error: Found extra flags: identityManagement
at Object.<anonymous> (C:\Users\Hoodi\AppData\Roaming\npm\node_modules\protractor\built\cli.js:172:15)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Hoodi\AppData\Roaming\npm\node_modules\protractor\bin\protractor:5:1)
at Module._compile (module.js:570:32)
My config file
// conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
useAllAngular2AppRoots: true,
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
// Use colors in the command line report.
showColors: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 60000,
},
onPrepare: function() {
require('../../lib/waitReady.js');
},
capabilities :{
browserName : 'chrome',
}
}
console.dir("argv: " + process.argv)
switch(process.argv[3]) {
case '--identityManagement':
exports.config.specs = ['./identityManagement.js'];
break;
default:
exports.config.specs = ['./identityManagement.js'];
}
I tried executing above script using protractor as well as "npm run" command, but in both cases i am getting same error. command that i used
protractor ./conf.js --identityManagement
and
npm run im
This actually works on my other system. npm and node version of system where this works are
node v7.2.1
npm v3.10.10
And where is doesnt work
node v7.4.0
npm v4.0.5
My package.json file looks like this
{
"name": "intelliflash",
"author": "Vishwanath Rawat <rawat#tegile.com>",
"description": "IntelliFlash tests",
"scripts": {
"im": "protractor ./conf.js --identityManagement"
}
}
Please help.
It has nothing to do with your npm or node versions, Latest release of Protractor 5.0 has put a check in cli for unidentified flags as you are putting with the help of process.argv.
You can solve this by disabling the flag checks:
protractor ./conf.js --identityManagement --disableChecks
For more details please refer the Protractor 5.0 changelog
Note: min node version now is v6.9.x which supports this version of protractor

VS 2015 Gulp Failed to load message

I'm just getting started with gulp in a .NET 4.6 project and I'm getting the error "Failed to load" in task runner explorer. My gulpfile is:
var gulp = require('gulp');
var inject = require('gulp-inject');
var concat = require('gulp-concat');
var print = require('gulp-print');
gulp.task('default', function () {
console.log('Hello Gulp!');
});
gulp.task('css-task', function () {
var target = gulp.src('./index.html');
var customCssStream = gulp.src(['./bower_components/bootstrap/dist/css/bootstrap.min.css']);
return target
.pipe(inject(customCssStream.pipe(print())
.pipe(concat('appStyles.css'))
.pipe(gulp.dest('./Content/css')), { name: 'styles' }))
.pipe(gulp.dest('./'));
});
And the error is:
gulp-inject/src/inject/index.js:127 startTag, ^ SyntaxError:
Unexpected token , at exports.runInThisContext (vm.js:73:16) at
Module._compile (module.js:443:25) at Object.Module._extensions..js
(module.js:478:10) at Module.load (module.js:355:32) at
Function.Module._load (module.js:310:12) at Module.require
(module.js:365:17) at require (module.js:384:17) at Object.
(.../node_modules/gulp-inject/index.js:4:28) at Module._compile
(module.js:460:26) at Object.Module._extensions..js (module.js:478:10)
I was able to get the "Hello Gulp!" task to run, but once I add gulp-inject I see the problem.
Turns out the problem was related to the version of node.js that Visual Studio 2015 installed not being compatible with node-inject module. After I installed version 4.4.2 of node.js and pointed visual studio at it as described here it now compiles.

Getting an error when I run NPM live-server

Here's the server I'm using, https://www.npmjs.com/package/live-server. However, when I try to use ~/.live-server.json as the configuration file, I always fail... Here's what I have in the file, and it's very simple.
{
port: "8001"
}
Then I have this error when I run live-server
undefined:2
port: "8001"
^
SyntaxError: Unexpected token p
at Object.parse (native)
at Object.<anonymous> (/usr/local/lib/node_modules/live-server/live-server.js:17:20)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
I don't know why this is happening.
Property names in JSON must be quoted (JSON is not JavaScript):
{
"port": "8001"
}
It should be:
{
"port": 8001
}
Add explanation: well, in JSON, name should always double quoted, and value should also be double quoted, except number (if you double quote a number, it becomes a string). Like this:
{
"name1": "stringValue",
"name2": aNumber
}

Resources