grunt icon indicating copy to clipboard operation
grunt copied to clipboard

Use require() when loading NPM tasks

Open rbelouin opened this issue 11 years ago • 5 comments

I wrote a library using grunt to build itself. Let's call it L. I wrote a project using grunt to build itself, and using L as a dependency. Let's call it P. Both L and P are using the same grunt plugin. Let's call it G.

Because npm does install a library just once in a node_modules tree, here is the hierarchy of the P project after running npm install:

./P
./P/node_modules
./P/node_modules/G
./P/node_modules/L

But there is no ./P/node_modules/L/node_modules/G and that makes grunt fail to build L.

Why is grunt searching for a ./node_modules/<plugin>/package.json file instead of just requiring it like any other node module?

rbelouin avatar Sep 03 '14 14:09 rbelouin

I'm working on a PR for this, FYI.

vergenzt avatar Oct 02 '14 22:10 vergenzt

Thanks! :+1:

rbelouin avatar Oct 03 '14 12:10 rbelouin

Is there an evolution concerning this issue/the PR? I've the same problem and can't find any other solution to solve it.

GauthierPLM avatar Nov 17 '15 09:11 GauthierPLM

Any news on this? I have the same problem, Grunt can't find its modules when called from a dependency's postinstall script.

Here is a simple example with Yarn and an example package that runs Grunt in its postinstall script:

pierre@pierre ~> yarn global add https://github.com/heroku-examples/node-grunt.git --ignore-engines
yarn global v1.3.2
[1/4] Resolving packages...
warning https://github.com/heroku-examples/node-grunt.git > grunt > [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
warning https://github.com/heroku-examples/node-grunt.git > grunt > glob > [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
warning https://github.com/heroku-examples/node-grunt.git > grunt > findup-sync > glob > [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
warning https://github.com/heroku-examples/node-grunt.git > grunt > glob > [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[1/1] ⡀ node-grunt
[-/1] ⡀ waiting...
[-/1] ⡀ waiting...
[-/1] ⡀ waiting...
error /home/pierre/.config/yarn/global/node_modules/node-grunt: Command failed.
Exit code: 3
Command: grunt uglify
Arguments: 
Directory: /home/pierre/.config/yarn/global/node_modules/node-grunt
Output:
>> Local Npm module "grunt-contrib-uglify" not found. Is it installed?

Grunt looks for grunt-contrib-uglify in /home/pierre/.config/yarn/global/node_modules/node-grunt/node_modules/ but it is installed in /home/pierre/.config/yarn/global/node_modules/.

So this issue prevents the installation of some NPM packages.

Rudloff avatar Nov 17 '17 22:11 Rudloff

I found a workaround: requiring grunt-loadnpmtasks in the dependency's Gruntfile fixes the issue. I would prefer this to fixed in Grunt though since grunt-loadnpmtasks has not been updated since 2016.

Rudloff avatar Nov 17 '17 22:11 Rudloff