Cannot find module 'findup-sync' on running grunt

Viewed 2195

I am working in a project previously built. This project was built using Node and Grunt. I have a Gruntfile.js in the root folder of the project.

I installed grunt both locally and global, using

npm i grunt
npm i -g grunt

After, I installed grunt-cli both locally and global, using

npm i grunt-cli
npm i -g grunt-cli

And when I try to run any grunt command (develop, init, etc), I get the error

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'findup-sync'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/usr/lib/nodejs/grunt-cli/bin/grunt:8:14)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

I searched in many forums and here too, but I haven't found an answer. Can anybody help me?

UPDATE

After lose more than 24 hours working on this error, I fixed it with the following steps:

  1. Install node-grunt-cli in Ubuntu via apt, like CPBL says in his comment
apt install node-grunt-cli

On OSX this wasn't necessary.

  1. Following the steps I found on this blog. However, I also needed to run the command
grunt develop

as a sudo, even though changing the permissions of many folders.

2 Answers

Thanks to Pablo Lopes for putting me on the right track (see his question which includes the answer). I resolved my issue by:

  1. Installing node-grunt-cli via apt: sudo apt install node-grunt-cli

  2. Running grunt with sudo: sudo grunt

This isn't an ideal fix because it requires using sudo when running grunt - which shouldn't be necessary.

For me, installing via apt was the cause of the issue. Installing via npm npm install grunt -g corrected the problem. Given an existing global grunt install from apt, you might need to add --force to overwrite.

Related