In Gruntfile.js' initConfig function, I have the following:
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;',
concat: {
options: {
banner: '<%= banner %>',
stripBanners: true
},
dist: {
src: ['src/<%= pkg.name %>.js'],
dest: 'dist/<%= pkg.name %>.js'
}
},
I'm creating the pkg variable and then attempting to pull the name from the object under concat.dist, because this is coming from a new grunt-init template. I'm getting Cannot read property 'name' of undefined when running concat:dist. I've verified the existence of the file and the node "name" in the package.json" file.
Given I'm new to node, I'm not sure if these closures persist when calling grunt tasks and if they do, am I using the wrong convention? Is this even possible?
My guess is that it can't read your
package.jsonfile for some reason. Either because it doesn't exist (named differently perhaps?) or doesn't have read permissions. You can create a simple test to see if you can access the file from Grunt:Now just run
grunt logvarfrom the command line. If you still get the error, well then we've eliminated anything else, and that means yourpackage.jsonfile is inaccessible. I would recommend checking that it is in the same directory asGruntfile.jsand that it has read permissions.