Node.js dependency not found even if installed - node.js

I'm trying to minify a whole folder of css files using minify-all.
But when I run: minify-all, I get:
Air-di-Giacomo:css jack$ sudo minify-all .
found file: alpha.css
/usr/local/lib/node_modules/minify-all/node_modules/node-minify/lib/node-minify.js:104
throw new Error(bin + ' not found !');
^
Error: uglifyjs not found !
at getPath (/usr/local/lib/node_modules/minify-all/node_modules/node-minify/lib/node-minify.js:104:17)
at Object.minify.fn.compress (/usr/local/lib/node_modules/minify-all/node_modules/node-minify/lib/node-minify.js:132:27)
at Object.minify (/usr/local/lib/node_modules/minify-all/node_modules/node-minify/lib/node-minify.js:83:10)
at /usr/local/lib/node_modules/minify-all/index.js:30:13
at /usr/local/lib/node_modules/minify-all/index.js:14:13
at Array.forEach (native)
at walk (/usr/local/lib/node_modules/minify-all/index.js:10:36)
at minifyAll (/usr/local/lib/node_modules/minify-all/index.js:25:5)
at Object.<anonymous> (/usr/local/lib/node_modules/minify-all/index.js:45:5)
at Module._compile (module.js:409:26)
I already tried the following commands:
sudo npm install -g uglifyjs
and also to reinstall it in the correct order (never know):
sudo npm remove -g minify-all
sudo npm remove -g uglifyjs
sudo npm install -g uglifyjs
sudo npm install -g minify-all
and finally, in despair, I did:
cd /usr/local/lib/node_modules/minify-all/
sudo npm install uglifyjs
But I still get that error!
This seems to me a node dependency problem, and maybe for some of you it is a stupid problem, do you know how can I solve this?
Thanks in advance.

Found a solution by install it locally.
cd /../myCssFolder/
npm init
...
npm install uglifyjs
npm install minify-all
minify-all .
of course I prefer to have it globally so I can skip the npm project installation everytime... Any suggestions?

Global modules always install in NODE_PATH/bin。
why not print echo $path in terminal, Is there NODE_PATH/bin in it ?
if not, you can update ~/.bashrc(if you use bash) or ~/.zshrc(if you use zsh)
export PATH="OLD_PATH:NODE_PATH/bin"
The OLD_PATH is the older one.

Related

Can't find correctly node and npm instances in ubuntu

I've a problem for use the node and npm install in my linux.
This hade started when in a project that I work, it have some problems with my global node, I don't remember what was my version, but the project is 10.13.0 and I could't build it.
So,I installed the version with .taz with below steps:
apt autoremove nodejs
extract .taz for /opt/node-v10.13.0-linux-x64
put path in ~/.profile and ~/.bashrc (found in net)
export NODEJS_HOME=/opt/node-v10.13.0-linux-x64/bin
export PATH=$NODEJS_HOME:$PATH
executed . ~/.profile ~/.bashrc
Well, after that my node -v worked but node hello got this error
internal/modules/cjs/loader.js:582
throw err;
^
Error: Cannot find module '/home/gustavo-rey/Área de Trabalho/vue-curso/vue-cli/bla'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3
However, my npm stoped to work with this error:
bash: /usr/bin/npm: File or directory not found
Can you help with this? I can't change my node version...
Resolution
With the Jatin's help, I could install the correctly version with sudo n [version.number], however, I've needed to remove my old aplication from the $PATH:
$ echo $PATH
/opt/node-v10.13.0-linux-x64/bin:/opt/node-v10.13.0-linux-x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
clear the npm cache:
npm cache clean -f
Install n, Node’s version manager:
npm install -g n
With the n module installed, you can use it to:
Install the latest stable version: sudo n stable
Install the latest release: sudo n latest
Install a specific version: sudo n [version.number]
For the permissions
first check the permissions of /opt/node-v10.13.0-linux-x64/lib/node_modules/n( please check if its the correct path) by using this command
ls -la /opt/node-v10.13.0-linux-x64/lib/node_modules/n
pretty sure it might be owned by root or some other user.
Then run whoami
and finally
sudo chown -R $USER /opt/node-v10.13.0-linux-x64/lib/node_modules/n

getting error when using -g in npm

when I try to install any package globally, I get multiple errors. have a look at the image
the errors in the terminal
Thanks all.
When you install any global package just add sudo prefix. sudo npm install -g express
If you want to install packages globally with the "g"-parameter you must be root.
It's easy to just run sudo npm install -g express to successfully install express.
But a long time solution for the permission access, run chown -R YOUR_USERNAME /usr/lib/node_modules from your terminal so that you will not have to include sudo in your subsequent installation using -g

Executing local (--save-dev) tools by npm

I just installed bower via npm install bower --save-dev because I want to have this available for everybody who checks the branch out and runs "npm update". I knew how to execute bower if I installed it with npm install bower -g but how do I actually execute it now?
this way does not satisfy me:
./node_modules/bower/bin/bower -v
Isn't there something like npm tools bower -v?
No, there is no npm tools command. But here is an alternative solution.
If your shell is bash, you can add function into your .bashrc.
# ~/.bashrc
function npm-tools {
(PATH=$(npm bin):$PATH; eval $#;)
}
Then you can run command like following to achieve what you want.
# $ tree node_modules/ -L=1
# node_modules/
# └── bower
$ ./node_modules/bower/bin/bower -v
1.7.9
$ npm-tools bower -v
1.7.9

Error: EACCES when creating new Ember project

I just installed Linux Mint (version 17.2) and I'm trying to install Ember. Everything seemed to go fine, but I'm getting this error when I run ember new testProject.
create vendor/.gitkeep
EACCES, mkdir '/home/mkm/.npm/mkdirp/0.4.2'
Error: EACCES, mkdir '/home/mkm/.npm/mkdirp/0.4.2'
at Error (native)
Per a recommendation in the Ember Documentation I used this guide to install Node.js and NPM. Some of what I've read suggest the issue is nodejs was installed with sudo, but apt-get failed when I didn't use sudo.
I attempted to run the new project anyway. bower install completed successfully. But ember serve failed with Cannot find module 'chalk'.
--Version Info
$ ember --version
version: 1.13.8
Could not find watchman, falling back to NodeWatcher for file system events.
Visit http://www.ember-cli.com/user-guide/#watchman for more info.
node: 0.12.7
npm: 2.13.4
os: linux x64
The only command that was needed to run with sudo for me was:
npm install
I suggest you delete node_modules/ in your project directory completely, then run:
sudo npm install
You can also add option --verbose to see if everything is correctly installing and installation isn't stuck.
You could also change permissions for .npm directory to avoid some problems like that in future:
sudo chmod 777 -R /home/mkm/.npm
You can use following commands to install and use npm without sudo:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | NVM_DIR="/home/your-user-name/.nvm" bash
export NVM_DIR="/home/your-user-name/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install 0.12
nvm alias default 0.12
npm install -g ember-cli
npm install -g bower
npm install -g phantomjs
Here is a link to nvm repository with latest version and documentation: https://github.com/creationix/nvm

npm upgrade with homebrew

When node (v.0.10.33) is installed with homebrew (v. 0.9.5), at one point it says:
==> Caveats
If you update npm itself do NOT use the npm upgrade command
Instead execute:
npm install -g npm#latest
So, what exactly is npm upgrade and what is the difference with npm install -g npm#latest?
-- edit 2015
the problem doesn't exist anymore with the current version of node. (but I never had an answer to what npm upgrade is?)
Use npm install to install a package and npm update to update a package.
That Homebrew npm caveat was removed after the issue with npm update -g was fixed.
npm comes bundled with node, both part of Node.js install --- no need to install separately
Below are the steps to install Node.js from source (OSX/linux)
Issue cmds as yourself NOT root (sudo)
to start fresh remove prior node and npm installs as well as these :
sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm ~/.npm_ignore
sudo mv ~/tmp ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore
download source from : http://nodejs.org/download/
cd freshly-downloaded-dir
define environment variable NODE_PATH as the dir for subsequent module installs
export NODE_PARENT=${HOME}/nodejs-v0.10.33
export PATH=${NODE_PARENT}/bin:${PATH}
export NODE_PATH=${NODE_PARENT}/lib/node_modules
./configure --prefix=${NODE_PARENT}
make
make install # IMPORTANT this is NOT using sudo
# not wanted since installing into $USER owned $NODE_PARENT
which puts it into dir defined by above --prefix
when you use syntax : npm install -g some_cool_module
the -g for global installs it into dir $NODE_PATH and not your $PWD
Now put above three export xxx=yyy
commands into your ~/.bashrc or some such to persist these environment variable changes

Resources