运行 Grunt 任务 returns 错误

Running Grunt task returns error

我目前正在尝试使用 this 从我的 CSS 文件中删除未使用的 CSS。出于某种原因,我不断收到无法解释的错误:

module.exports = function(grunt) {

  require('load-grunt-tasks')(grunt);

  grunt.initConfig({
    purifycss: {
      options: {

      },
      target: {
        src: ['templates/**/*.html'], // Observe all html files
        css: ['static/css/main.css'], // Take all css files into consideration
        dest: 'static/css/newcss.css' // Write to this path
      }
    }
  });

  grunt.registerTask('default', ['purifycss']);
};

当我在命令行中 运行 grunt 时,我得到:

>> TypeError: Cannot read property 'dependencies' of null
Warning: Task "default" not found. Used --force, continuing.

Done, but with warnings.

有人知道为什么会这样吗?

当您的 package.json 丢失而您使用的是 load-grunt-tasks 时,就会发生这种情况。 运行 npm init,按照提示进行操作,然后检查生成的依赖项和 devDependencies 是否符合您的预期。