简体   繁体   English

我删除了package.json和Gruntfile.js,现在Grunt将不会加载依赖项

[英]I deleted package.json and Gruntfile.js and now Grunt will not load dependencies

So by accident I deleted my package.json and Gruntfile folder from my project directory and before I did that I already ran grunt and grunt jshint and it ran perfectly fine. 因此,我无意中从项目目录中删除了package.json和Gruntfile文件夹,在此之前,我已经运行了gruntgrunt jshint ,并且运行得非常好。 I re-made both files (package.json and Gruntfile.js) and now when I try to run grunt or grunt jshint It tells me.. 我重新制作了两个文件(package.json和Gruntfile.js),现在当我尝试运行gruntgrunt jshint它告诉我..

PS C:\Users\Vincent\desktop\projects\kittenbook> grunt jshint
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
>> Local Npm module "grunt-contrib-jshint" not found. Is it installed?
Warning: Task "jshint" not found. Use --force to continue.

Then Powershell crashes soon after. 然后,Powershell很快便崩溃了。

Npm works I already checked and I know Grunt is obviously installed. 我已经检查了Npm的工作,并且我知道显然已安装了Grunt。

Here's my Gruntfile.js which I had to re-make. 这是我必须重新制作的Gruntfile.js。 It ran perfectly fine before I deleted my package.json file.. 在删除package.json文件之前,它运行得非常好。

module.exports = function(grunt) {
    grunt.initConfig({
        concat: {
        release: {
            src: ['js/values.js', 'js/prompt.js'],
            dest: 'release/main.js'
        }
      },
      copy: {
          release: {
              src: 'manifest.json',
              dest: 'release/manifest.json'
          }
      },
      jshint: {
          files: ['js/values.js', 'js/prompt.js']
      }
    });

    // Load Grunt plugin
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-jshint');

    // Register tasks
    grunt.registerTask('default', ['jshint', 'concat', 'copy']);

};

Here's the new package.json file 这是新的package.json文件

{
  "name": "kittenbook",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-concat": "^0.3.0",
    "grunt-contrib-copy": "^0.5.0",
    "grunt-contrib-jshint": "^0.6.5",
    "grunt-contrib-watch": "^1.0.0"
  }

}

Also Should I run the Gruntfile above even though I already ran it the first time? 另外,即使我已经第一次运行Gruntfile,也应该在上面运行它吗? Will that mess anything up? 那会乱成一团吗?

I hope this is not too confusing. 我希望这不要太令人困惑。 I'm new at programming. 我是编程新手。 Thanks! 谢谢!

Update: When I try to run npm install 更新:当我尝试运行npm install

PS C:\Users\Vincent> cd desktop/projects/kittenbook
PS C:\Users\Vincent\desktop\projects\kittenbook> npm install
npm WARN package.json kittenbook@1.0.0 No description
npm WARN package.json kittenbook@1.0.0 No repository field.
npm WARN package.json kittenbook@1.0.0 No README data
npm WARN package.json kittenbook@1.0.0 No license field.

UPDATE: The mistake I made was that the Gruntfile.js was outside of my projects folder.. Wow.. lol. 更新:我犯的错误是Gruntfile.js在我的项目文件夹之外..哇..大声笑。 Problem solved. 问题解决了。

In command prompt go to the directory of your project and run the following command. 在命令提示符下,转到项目目录,然后运行以下命令。

npm install

You may have to open command prompt with administrator privileges for this to work. 您可能必须使用管理员权限打开命令提示符,此命令才能起作用。

This will install all the npm modules defined in the package.json file. 这将安装package.json文件中定义的所有npm模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM