Node.js and Grunt install on Windows - node.js

I have Node.js installed and I have ran npm install -g grunt-cli I have cd to the directory of the app I am to work on and followed the instructions here. When I run grunt in my cmd it returns
module.js:340
throw err;
^
Error: Cannot find module '\\Server\username$\Redirected\AppData\npm\AppData\npm\node_modules\grunt-cli'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
I really am not sure why its trying to read from \AppData\npm\AppData\npm\ as I haven't made any changes and I don't know how to change the grunt location
But when I use npm install -g grunt-cli it downloads and installs to the following \\Server\username$\Redirected\AppData\npm\node_modules\grunt-cli

You need to change the global install directory.
Try this ..
In C:\Users{username}\, create .npmrc file with contents:
prefix = "C:\\Users\\{username}\\AppData\\Roaming\\npm"
This is discussed more fully here:
Change default global installation directory for node.js modules in Windows?

Related

Cannot find module 'findup-sync' on running grunt

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:
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.
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.
Thanks to Pablo Lopes for putting me on the right track (see his question which includes the answer). I resolved my issue by:
Installing node-grunt-cli via apt:
sudo apt install node-grunt-cli
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.

Error: Cannot find module 'commander'

when I m running sails -v, sails lift or even installing npm I m getting this error Please help -
Error: Cannot find module 'commander'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/sails/bin/_commander.js:6:15)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
Most likely commander is missing from package.json. Install it and add it to package.json by doing:
npm install commander --save
Install commander globally.
sudo npm install commander -g
This will install commander module under/usr/lib/node_modules/.
Uninstalling sails and reinstalling with 'sudo' resolved it.
npm uninstall sails -g
sudo npm install sails -g
When i try setup new app with the help of express-generator.
given error:Cannot find module 'commander'
Node version:12.16.1
switch node version :10.16.3
after switch node version is working fine..
In my case it was because of bad version of node. I've tried node 8.15.1 and it works.
On my end, after doing npm install, and attempt to run npm run watch I encountered this same issue of Error: Cannot find module 'commander'.
I did below:
// delete node_modules (can do manually) or command below
// rm -rf node_modules
npm install
And I was able to do npm run watch again.
This maybe because of corrupted packages.

Windows -installed node.js but npm not found

I thought npm is automatically installed with the latest node.js installer on Windows. However when I try and use npm in the command console I get the following error
C:npm install socketio
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\foo\node_modules\npm\bin\n
pm-cli.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
I checked and npm DOES exist in the nodejs Program Files directory. So is this a PATH environment issue? And if so, how do I resolve so I can use npm anywhere I open a command console window?
What version of the windows are you trying?
And also you need to check the dependencies are installed for more information check the link,
https://www.npmjs.org/package/socket.io

Error - Cannot find module 'broccoli'

I'm getting this error and cannot find any way to fix it. It occurs upon trying to execute broccoli build.
Error: Cannot find module 'broccoli' from '/Users/devel/Projects/broccoliTest'
at Function.module.exports [as sync] (/usr/local/lib/node_modules/broccoli-cli/node_modules/resolve/lib/sync.js:32:11)
at Object.<anonymous> (/usr/local/lib/node_modules/broccoli-cli/bin/broccoli:7:28)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
I've just installed sudo npm install -g broccoli and sudo npm install -g broccoli-cli. The broccoli executable file is fine, obv:
>which broccoli
/usr/local/bin/broccoli
so it seems that the broccoli module is not correctly installed, although no error occured in the installation process.
ls /usr/local/lib/node_modules/broccoli
CHANGELOG.md LICENSE README.md docs lib node_modules package.json templates
Any ideas?
Globally installed packages aren't made available to require(), by design:
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line.
If you need both, then install it in both places, or use npm link.
You'll have to also install it locally, relative to your scripts:
cd /Users/devel/Projects/broccoliTest
npm install broccoli
You can execute you command using a relative path like this:
./node_modules/.bin/broccoli build
To avoid that you can use broccoli-cli to take care of figuring out the path for you.
yarn add -D broccoli-cli
npm install --save-dev broccoli-cli
Or you can just install it globally.

nodejs on windows: nmp install does not download modules

I have installed a 64bit nodejs on my windows7 (classical installation, no errors during installation)
I created a simple package.json
{
"name":"chat",
"version":"0.0.1",
"private":"true",
"dependecies":{
"socket.io":"0.9.16",
"express":"3.1.0",
}
}
then install it with
npm install
and... Nothing: no packages are downloaded !
(if I make an error in the package.json, I got errors messages at npm install)
Everything seems to be fine, except that npm install does not install anything.
and of course when trying to luch a nodejs project, I got:
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
You have a typo in your package.json, it should be "dependencies".
Make sure to generate your package.json with npm init, so to avoid this kind of problems.

Resources