Grunt plugins not installed at current location

I work with Mac OS X 10.7.5, and I use Grunt to concretize some js files and minimize them. Now I want to also reduce my css files. Since grunt does not provide any functionality, I wanted to install the grunt plugin for it. According to the instructions, I have to connect to the root folder of my projects and install the plugin with npm number. So I did the following:

cd <PROJECT_ROOT> npm install grunt-contrib-css 

Instructions for the plugin are given here: https://npmjs.org/package/grunt-contrib-mincss I opened the grunt.js file and added

 grunt.loadNpmTasks('grunt-contrib-mincss'); 

But when I try to run grunt, I just get

 Local Npm module "grunt-contrib-mincss" not found. Is it installed? <WARN> Task "mincss" not found. Use --force to continue. </WARN> 

The installation works without problems, and npm ls lists the module.

Any ideas what I did wrong? Thank you very much!

UPDATED

When I joined a similar project

 cd ~/Sites/path/to/project 

and then install the plugin

 sudo npm install grunt-contrib-mincss 

the module is actually installed in

 ~/node_modules/grunt-contrib-mincss 

I could copy the files to the root directory of my projects (which works), but this is strange, right?

UPDATE 2 I updated node and tried again. The console output is shown below.

 me:~ Fritz$ node -v v0.8.10 me:~ Fritz$ npm -v 1.1.62 me:~ Fritz$ mkdir ./Sites/npm-test me:~ Fritz$ cd ./Sites/npm-test/ me:npm-test Fritz$ sudo npm install grunt-contrib-mincss Password: npm http GET https://registry.npmjs.org/grunt-contrib-mincss npm http 304 https://registry.npmjs.org/grunt-contrib-mincss npm http GET https://registry.npmjs.org/gzip-js npm http GET https://registry.npmjs.org/clean-css npm http GET https://registry.npmjs.org/grunt-contrib-lib npm http 304 https://registry.npmjs.org/gzip-js npm http 304 https://registry.npmjs.org/clean-css npm http 304 https://registry.npmjs.org/grunt-contrib-lib npm http GET https://registry.npmjs.org/crc32 npm http GET https://registry.npmjs.org/deflate-js npm http GET https://registry.npmjs.org/optimist npm http 304 https://registry.npmjs.org/deflate-js npm http 304 https://registry.npmjs.org/crc32 npm http 304 https://registry.npmjs.org/optimist npm http GET https://registry.npmjs.org/wordwrap npm http 304 https://registry.npmjs.org/wordwrap grunt-contrib-mincss@0.3.0 ../../node_modules/grunt-contrib-mincss ├── grunt-contrib-lib@0.3.0 ├── gzip-js@0.3.1 ( crc32@0.2.2 , deflate-js@0.2.2 ) └── clean-css@0.4.2 ( optimist@0.3.4 ) 

Why is the plugin installed externally? Or is there a way to determine the actual place where it is installed?

+4
source share
5 answers

This installation method worked for me:

  • cd <PROJECT_ROOT> .
  • Run npm install grunt-contrib-mincss .
  • Created a test file in the current directory with the following test content:

     module.exports = function(grunt) { grunt.initConfig({ mincss: { compress: { files: { "path/to/output.css": ["path/to/input_one.css", "path/to/input_two.css"] } } } }); grunt.loadNpmTasks('grunt-contrib-mincss'); grunt.registerTask('default', 'mincss'); }; 
  • My directory structure looks at this moment (please check this, if some files are not located or in some other folder, then this may be the reason why it does not work):

     <PROJECT_ROOT> / node_modules / grunt-contrib-mincss/ grunt.js 
  • Run grunt in the terminal.

Script worked.

Possible reasons why this didn't work in your case:

  • You have installed the plugin globally (with the -g argument).
  • You installed it in a subfolder (grunt.js and node_modules should be in the same folder).

Please, check him.

+3
source

I had a similar problem on Ubuntu 12.04 for the grunt-jasmine-task module (same error message as above). This solved the problem for me:

  • Manually create the node_modules folder in the root of the project.
  • Run npm install grunt-jasmine-task again.
+4
source

I saw cases when there was no package.json file, due to which the modules were installed globally. I am not sure which version worked at that time, since it was not my car.

Next time try running npm init before installing the modules. After that, install with npm install grunt-contrib-css --save so that it is added to your package.json file. You can also use --save-dev to add it to your devDependencies.

+1
source

In my case, I forgot to add:

 grunt.loadNpmTasks('grunt-jsdoc-plugin'); 

in grunt.js, so it should look like this:

 module.exports = function(grunt) { // Project configuration. grunt.initConfig({ jsdoc : { dist : { src: ['frontend/js/**/*.js'], dest: 'docs/frontend' } } }); grunt.loadNpmTasks('grunt-jsdoc-plugin'); }; 
0
source

If you look in the grunt-contrib-mincss folder, there is a readme file, they changed the name to grunt-contrib- mincss to grunt-contrib- cssmin .

In any case, this is not your (and my) mistake. Xd

0
source

Source: https://habr.com/ru/post/1436171/


All Articles