lbottoni
lbottoni

Reputation: 1032

grunt Cannot read property 'name' of undefined

i try grunt on my windows machine. if i use yo webapp all work fine, but if i try to use grunt on exist project i have some problem.

my Gruntfile.js

module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner:"<%= pkg.name %>"
});
//Load the plugin that provides the "uglify" task.
//grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.log.writeln("____________ log __________________");
grunt.log.writeln(grunt.pkg.name);
grunt.log.writeln(grunt.pkg.banner);
grunt.log.writeln();
grunt.log.writeln();
// Default task(s).
grunt.registerTask('default');}

package.json

{
"name": "bsworld",
"version": "0.1.0",
"description": "mio progetto personale",
"devDependencies": {
"grunt": "^0.4.1"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "grunt test"
}
}

this is the output of grunt --verbose

Initializing Command-line options: --verbose Reading "Gruntfile.js" Gruntfile...OK Registering Gruntfile tasks. Initializing config...OK ______ log ____________ Loading "Gruntfile.js" tasks...ERROR >> TypeError: Cannot read property 'name' of undefined >> at Object.module.exports (C:\Apache\htdocs\bottonisworld.com\Gruntfile.js:13:29)

at loadTask (C:\Apache\htdocs\bottonisworld.com\node_modules\grunt\lib\grunt    \task.js:325:10)
at Task.task.init (C:\Apache\htdocs\bottonisworld.com\node_modules\grunt\lib\grunt\task.js:437:5)
at Object.grunt.tasks (C:\Apache\htdocs\bottonisworld.com\node_modules\grunt\lib\grunt.js:120:8)
at Object.module.exports [as cli] (C:\Apache\htdocs\bottonisworld.com\node_modules\grunt\lib\grunt\cli.js:38:9)
at Object.<anonymous> (C:\Users\l.bottoni\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt:45:20)
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)

No tasks specified, running default tasks. Running tasks: default Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.

why grunt don' load the file json?????

Upvotes: 0

Views: 3246

Answers (1)

lbottoni
lbottoni

Reputation: 1032

resolved, the json is loaded but i must get data with the correct method

grunt.log.writeln(grunt.config("pkg.name"));

Upvotes: 0

Related Questions