NPM global install "cannot find module" - node.js

I wrote a module which I published to npm a moment ago (https://npmjs.org/package/wisp)
So it installs fine from the command line:
$ npm i -g wisp
However, when I run it from the command line, I keep getting an error that optimist isn't installed:
$ wisp
Error: Cannot find module 'optimist'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/usr/local/lib/node_modules/wisp/wisp:12:10)
at Object.<anonymous> (/usr/local/lib/node_modules/wisp/wisp:96:4)
at Module._compile (module.js:449:26)
at Object.exports.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:68:25)
at compileScript (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:135:29)
at fs.stat.notSources.(anonymous function) (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:110:18)
However, I have specified in package.json as a dependancy:
{
"name": "wisp",
"author": "Brendan Scarvell <bscarvell#gmail.com>",
"version": "0.1.0",
"description": "Global nodejs file server",
"dependencies": {
"optimist": "~0.3.4"
},
"repository": "git://github.com/tehlulz/wisp",
"bin": {
"wisp" : "./wisp"
}
}
Does anyone know what to do to get this running? I know its to do with the bin part adding the executable to bin and the node_modules in that directory being empty. No idea how to resolve this.

For anyone else running into this, I had this problem due to my npm installing into a location that's not on my NODE_PATH.
[root#uberneek ~]# which npm
/opt/bin/npm
[root#uberneek ~]# which node
/opt/bin/node
[root#uberneek ~]# echo $NODE_PATH
My NODE_PATH was empty, and running npm install --global --verbose promised-io showed that it was installing into /opt/lib/node_modules/promised-io:
[root#uberneek ~]# npm install --global --verbose promised-io
npm info it worked if it ends with ok
npm verb cli [ '/opt/bin/node',
npm verb cli '/opt/bin/npm',
npm verb cli 'install',
npm verb cli '--global',
npm verb cli '--verbose',
npm verb cli 'promised-io' ]
npm info using npm#1.1.45
npm info using node#v0.8.4
[cut]
npm info build /opt/lib/node_modules/promised-io
npm verb from cache /opt/lib/node_modules/promised-io/package.json
npm verb linkStuff [ true, '/opt/lib/node_modules', true, '/opt/lib/node_modules' ]
[cut]
My script fails on require('promised-io/promise'):
[neek#uberneek project]$ node buildscripts/stringsmerge.js
module.js:340
throw err;
^
Error: Cannot find module 'promised-io/promise'
at Function.Module._resolveFilename (module.js:338:15)
I probably installed node and npm from source using configure --prefix=/opt. I've no idea why this has made them incapable of finding installed modules. The fix for now is to point NODE_PATH at the right directory:
export NODE_PATH=/opt/lib/node_modules
My require('promised-io/promise') now succeeds.

add this to beginning of prog(mac):
module.paths.push('/usr/local/lib/node_modules');

By default node does not look inside the /usr/local/lib/node_module for loading global modules.
Refer the module loading explained in http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
So either you have to
1)add the /usr/local/lib/node_module to NODE_PATH and export it
or
2)copy the installed node modules to /usr/local/lib/node .
(As explained in the link for loading module node will search in this path and will work)

The following generic fix would for any module. For example with request-promise.
Replace
npm install request-promise --global
With
npm install request-promise --cli
worked (source) and also for globals and inherits
Also, try setting the environment variable
NODE_PATH=%AppData%\npm\node_modules

For some (like me) that nothing else worked, try this:
brew cleanup
brew link node
brew uninstall node
brew install node
Hope it helps someone :)

I got the "optimist" module error and I just did "npm install" to resolve it. went past that error.
https://github.com/mbloch/mapshaper/issues/12

On windows if you just did a clean install and you get this you need blow away your npm cache in \AppData\Roaming

$ vim /etc/profile.d/nodejs.sh
export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript

For Windows, from Nodejs cannot find installed module on Windows? what worked for me is running npm link as in
npm link wisp

I did this in simple way...
Un-Install node from control panel [Windows 7]
Install node again
Install protractor
npm install --global --verbose protractor
Update web driver manager.
works fine for me.
Hope this helps you....

I got this error Error: Cannot find module 'number-is-nan' whereas the module actually exists. It was due to a bad/incomplete Node.js installation.
For Windows , as other answers suggest it, you need a clean Node installation :
Uninstall Node.js
Delete the two folders npm and npm_cache in C:\Users\user\AppData\Roaming
Restart Windows and install Node.js
Run npm initor (npm init --yes for default config)
Set the Windows environment variable for NODE_PATH. This path is where your packages are installed. It's probably something likeNODE_PATH = C:\Users\user\node_modules or C:\Users\user\AppData\Roaming\npm\node_modules
Start a new cmd console and npm should work fine
Note :
Try the last points before reinstalling Node.js, it could save you some time and avoid to re-install all your packages.

For Mac User's It's Best use the manual installation:
To minimize the chance of permissions errors, you can configure npm to
use a different directory. In this example, it will be a hidden
directory on your home folder.
Back-up your computer before you start.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g.
if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
Reference : https://docs.npmjs.com/getting-started/fixing-npm-permissions

I have just met this problem of the axios module.
Then I tried this: run rm -rf node_modules and yarn.
And it works.

Had the same problem on one of the test servers running Ubuntu under root. Then created a new user using useradd -m myuser and installed everything (nvm, node, packages) as myuser. Now it's working fine.

In my case both node and npm were in same path (/usr/bin). The NODE_PATH was empty, so the npm placed the global modules into /usr/lib/node_modules where require(...) successfully find them.
The only exception was the npm module, which came with the nodejs package. Since I'm using 64 bit system, it was placed into /usr/lib64/node_modules. This is not where require(...) searches in case of empty NODE_PATH and node started from /usr/bin. So I had two options:
link /usr/lib64/node_modules/npm to /usr/lib/node_modules/npm
move modules from /usr/lib/node_modules/* to /usr/lib64/node_modules/ and set NODE_PATH=/usr/lib64/node_modules
Both worked. I'm using OpenSUSE 42.1 and the nodejs package from updates repository. Version is 4.4.5.

I had the same error as the OP, but digging through the logs I could see sh: node: command not found.
It turns out that the /usr/bin/node program (symlink) is no longer installed with apt install nodejs. Once symlinked /usr/bin/node' tonodejs,npm install -g #angular/cli` succeeded.
The proper way to install this on debian is apt install nodejs-legacy.

I had to add C:\Users\{Username}\AppData\Roaming\npm to my env variables and then i could install stuff.

Faced the same issue and got it resolved by adding the below line in my zshrc.
Based on your shell you can try adding in your rc file, for bash and zsh - bashrc/zshrc files present in your home location.
export NODE_PATH="/usr/local/lib/node_modules"
To directly add in zshrc file, run this command
echo 'export NODE_PATH="/usr/local/lib/node_modules"' >> ~/.zshrc

Alpine / Containerization
As mentioned elsewhere, the solution is to bake into your image,
NODE_PATH=/usr/local/lib/node_modules/
I've also opened up an issue upstream with npm apk so this gets set

Related

node-gyp 5 on Windows: Cannot find npm\node_modules\node-gyp\bin\node-gyp.js

Running npm 6.11.3, node-gyp 5.0.3, VS2019 on Windows 10 v1903, getting this error:
Cannot find module %AppData%\npm\node_modules\node-gyp\bin\node-gyp.js (where %AppData% is expanded to the actual user-specific path).
The error only happens if the build is invoked via npm, i.e.:
npm run build
The package.json file scripts section:
"scripts": {
...
"build": "node-gyp build",
}
If node-gyp build is invoked manually outside npm context, the error is gone.
How do I get rid of the error and still use npm scripts for making builds?
Figured it out.
After upgrading to node-gyp 5 on a Windows 10 build system, I started getting the infamous Error: Cannot find module ... npm\node_modules\node-gyp\bin\node-gyp.js, caused by node_modules\npm-lifecycle\node-gyp-bin being pushed on top of my PATH by npm, exactly as described here.
None of the existing remedies I've found and tried could solve this issue for me, including installing the latest windows-build-tools. Here's exactly what I tried, in the following order:
manually clean up the mess and duplicates in System PATH and User PATH environment vars
reboot
choco unistall nodejs
rd /s %AppData%\npm\
rd /s %AppData%\npm\
choco install nodejs
npm install -g npm#latest
npm install -g node-gyp#latest
npm install -g typescript#latest
I was still getting the missing node-gyp.js error. What did help was to properly set npm config set node_gyp to point to the correct node-gyp.js, as suggested here. Yet somehow the script from that thread didn't work properly for me (as well some other PowerShell/Batch scripts I tried).
Eventually, I've come up with the following PowerShell 6 one-liner that did the trick for me:
pwsh -Command npm config set node_gyp "`u{22}$(Join-Path $(npm root -g) -ChildPath 'node-gyp\bin\node-gyp.js')`u{22}"
Hope this helps others and future-me. I'd still recommend going through the above bullet list for clean troubleshooting.

sh: 1: node: Permission denied

Tried to run this command on ubuntu 18.04
npm install -g pngquant-bin
but I got this error,
[..................] | fetchMetadata: sill resolveWithNewModule npm-conf#1.1.3 checking installable status
npm WARN deprecated gulp-util#3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
/root/.nvm/versions/node/v10.8.0/bin/pngquant -> /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin/cli.js
> pngquant-bin#5.0.0 postinstall /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin
> node lib/install.js
sh: 1: node: Permission denied
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! pngquant-bin#5.0.0 postinstall: `node lib/install.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the pngquant-bin#5.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-08-12T18_08_02_197Z-debug.log
Do you do you know how to deal with this?
I tried every solution found in this articles yet not succeeded.
Got the same error sh: 1: node: Permission denied
So this worked for me
npm config set user 0
npm config set unsafe-perm true
These issues happen because of broken packages. Go to the main folder. If using Linux use command
sudo rm -rf node_modules.
After that run this command if you are using yarn
yarn install
If you are using npm run this command
npm install
Delete the node_modules and install it again
sudo rm -rf node_modules
npm install
in fact, npm can't use root account to install anything. if you use root account, npm will create a non-permission account to install. in this case, if the package need to execute writeFile or other operation which need permission, the error node: Permission denied will be raised.
so, you can choose optional arbitrary under:
npm install xxx --unsafe-perm
npm config set unsafe-perm true
create high-permission account dedicate to execute npm install
In my case it was a silly typo, I was forgotten to add node into the front of the start command in package.json. So I've changed:
"scripts": {
"start": "app/server.js"
}
... to:
"scripts": {
"start": "node app/server.js"
}
The /root/.npm/... log path in your original message shows you're already running as root, and (despite what others advise) I'd say this is most likely causing your problem.
My (limited) experience running Node as root is that most npm install runs get quite a long way, but then fail with some variation on the error you showed. The only reliable solution I've found is to not run Node or npm as root at all on Ubuntu. Just use a normal user account to download and unpack the Node installation.
At least one problem with running as root for me turned out to be because some dependency-of-a-dependency npm install script was calling setuid to switch to a less-privileged user. For some reason, it chose UID 500—which doesn't exist on Ubuntu—and consequently lost all its privileges. The 'Permission denied' errors were therefore because I was running as root; setuid doesn't work for a normal user.
I believe this is related to Error: setuid user id does not exist npm ERR! when npm install forever -g.
Solved my problem chmod -R a+x node_modules
As far as my understanding goes the os is blocking your ability to execute commands described in node_modules so by my understanding what this command does is say everything in node_modules is okay to execute.
By the time I found the solution it was 4 AM, so I didn't really bother to figure out what I actually did. If someone knows what -R a+x node_modules does exactly feel free to drop it in the commands and I will make an edit.
I make the chown to project user owner (in USERID) dir and resolv the "permission denied" problem:
sudo chown -R USERID.USERID *
Additionally (and this might be useful for docker) you can override this configuration setting globally via the environment variable npm_config_user -- for example:
ENV npm_config_user=root
I ran into the same error an nothing really helped. I found a medium article explaining how to set up an angular build management. For some reason adding
- npm link #angular/cli#13.2.5
to my build script made it. I basically added all of the recommendations above. So my build script now looks like this
- ...
- npm config set user 0
- npm config set unsafe-perm true
- npm i --force
- npm link #angular/cli#13.2.5
- ...
I hope it helps! I would be happy if someone could explain why it actually worked.
This is an old question but maybe someone still need some help.
This errors often is displayed because you have defined in the package.json just the path. For example:
{
// more definitions
"scripts": {
// other scripts
"getPax8Products": "<filepath>",
// more scripts
},
// more definitions
}
In this case, you need to:
Add the following lines in the very beggining of the script
#!/usr/bin/env node
'use strict';
Give the file execution permission
# in UNIX based
chmod +x <filepath>
You also can modify the package.json and add the node command. However, you need to be aware that NPM will run in the script's directory:
{
// more definitions
"scripts": {
// other scripts
"getPax8Products": "node <filepath>",
// more scripts
},
// more definitions
}
For Deploying with Docker:
make sure /node_modules is deleted or added to dockerignorefile
make sure /dist is deleted or added to dockerignorefile
the problem was solved for me by deleting both files
and build them in the container
For me, I had not installed my dependencies. node_modules did not exist, but I had jest installed globally apparently. Running npm ci and then running npm test solved my issue.
npm install lite-server --save-dev
packages.json:
"scripts": {
"dev": "lite-server",
},
"devDependencies": {
"lite-server": "^2.6.1"
}
npm run dev
I stuck with same issue when tried to install packages into AWS Sagemaker instance
The issue coming because NPM by default install new global packages into ~/.npm-global
When you run npm install -g by root, npm is try to install package into /root/.npm-global/..., and stuck with access denied.
Simply workaround to re-config global folder for npm.
(https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
Here is example of install obj2gltf
mkdir /npm-global
npm config set prefix '/npm-global'
export PATH=/npm-global/bin:$PATH
npm install -g obj2gltf
I had that error too and tried the above solutions without any change. My error was caused because I had Windows (11) with a WSL and NVM installed on both operating systems. I had to uninstall NVM on my Windows to resolve the conflicts.
I think if you develop in your WSL and have a resource installed on both operating systems, a dependency might point to the wrong operating system with the resource (in my case to the NVM on Windows). The WSL user didn't have sufficient permissions to perform any execution on the Windows machine, which lead to the error.
you need root user permission, just add sudo keyword before the command and write your password
sudo npm install -g pngquant-bin
Try to install node at project folder
npm install node

unable use any installed npm packages

I'm trying to use node on my fedora 21 installation. However whenever I install a package via npm I am not able to to call that package such as gulp.
npm install -g gulp
then : gulp run
error:
zsh: command not found: gulp
You need to point your global $PATH variable to the location of node. Otherwise, it will return that error.
Open your .zshrc file and ensure you see something like PATH=/usr/bin/node:$PATH (ensuring your directory is the proper one for node). You can find that directory location with the command npm -g bin.
If that doesn't work, comment below. Thanks
The directory where npm installed gulp is not in your path. To find out where it was installed, run npm -g bin and make sure the directory is in your path. Alternatively, execute gulp as $(npm -g bin)/gulp.

Error: Cannot find module 'webpack'

I'm just getting started with webpack and am having difficulty getting the multiple-entry-points sample to build. The webpack.config.js file in the example includes the line
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
which fails for me with the error
Error: Cannot find module '../../lib/optimize/CommonsChunkPlugin'
Searching around, I found other examples of using the CommonsChunkPlugin with the expression
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin("common.js");
which fails with the error
ReferenceError: webpack is not defined
Some more searching found a number of examples including
var webpack = require('webpack');
and my build now fails with
Error: Cannot find module 'webpack'
I'm at a loss as to how to proceed.
Link globally installed package to your project:
npm link webpack
Checkout the official documentation of yarn link.
I solved the same problem by reinstalling, execute these commands
rm -rf node_modules
rm -f package-lock.json
npm install
rm is always a dangerous command, especially with -f, please notice that before executing it!!!!!
While working on windows, I've installed webpack locally and it fixed my problem
So, on your command prompt, go to the directory of which you want to run webpack, install webpack locally (without the -g) and enjoy...
Run below commands in Terminal:
npm install --save-dev webpack
npm install --save-dev webpack-dev-server
Seems to be a common Windows problem. This fixed it for me:
Nodejs cannot find installed module on Windows?
"Add an environment variable called NODE_PATH and set it to %USERPROFILE%\Application Data\npm\node_modules (Windows XP), %AppData%\npm\node_modules (Windows 7), or wherever npm ends up installing the modules on your Windows flavor. To be done with it once and for all, add this as a System variable in the Advanced tab of the System Properties dialog (run control.exe sysdm.cpl,System,3)."
Note that you can't actually use another environment variable within the value of NODE_PATH. That is, don't just copy and paste that string above, but set it to an actual resolved path like C:\Users\MYNAME\AppData\Roaming\npm\node_modules
I was having this issue on OS X and it seemed to be caused by a version mismatch between my globally installed webpack and my locally installed webpack-dev-server. Updating both to the latest version got rid of the issue.
I was facing same problem, and I solved through this command, check this out will solve your issue.
rm -Rf node_modules
rm -f package-lock.json
npm install
Installing both webpack and CLI globally worked for me.
npm i -g webpack webpack-cli
If you have installed a node package and are still getting message that the package is undefined, you might have an issue with the PATH linking to the binary. Just to clarify a binary and executable essentially do the same thing, which is to execute a package or application. ei webpack... executes the node package webpack.
In both Windows and Linux there is a global binary folder. In Windows I believe it's something like C://Windows/System32 and in Linux it's usr/bin. When you open the terminal/command prompt, the profile of it links the PATH variable to the global bin folder so you are able to execute packages/applications from it.
My best guess is that installing webpack globally may not have successfully put the executable file in the global binary folder. Without the executable there, you will get an error message. It could be another issue, but it is safe to say the that if you are here reading this, running webpack globally is not working for you.
My resolution to this problem is to do away with running webpack globally and link the PATH to the node_module binary folder, which is /node_modules/.bin.
WINDOWS:
add node_modules/.bin to your PATH.
Here is a tutorial on how to change the PATH variable in windows.
LINUX:
Go to your project root and execute this...
export PATH=$PWD/node_modules/.bin:$PATH
In Linux you will have to execute this command every time you open your terminal. This link here shows you how to make a change to your PATH variable permanent.
On windows, I have observed that this issue shows up if you do not have administrative rights (i.e., you are not a local administrator) on the machine.
As someone else suggested, the solution seems to be to install locally by not using the -g hint.
for me, it is a wrong error feedback.
there was config error in webpack.config.js,
delete the file and start over solved my issue
Open npm command prompt and -- cd solution folder
and then
just run npm link webpack in NPM cmd prommt and re build..
You can try this.
npm install --only=dev
It works for me.
In my case helped me changing the parent folder name and remove some & from this name, you can also try changing the name or folder where you keep your code.
Nothing suggested above worked for me (including the NODE_PATH variable). I created a sym link of "node_modules" from my local folder to the global AppData(eg below) and it worked like charm.
C:\Users\mmoinuddin\AppData\Roaming\npm>mklink /D node_modules c:\essportreact\day1\node_modules
symbolic link created for node_modules <<===>> c:\essportreact\day1\node_modules
C:\essportreact\day1>webpack
Hash: 2a82a67f90f9aa05ab4a
Version: webpack 1.15.0
Just found out that using Atom IDE terminal did not install dependencies locally (probably a bug or just me). Installing git bash externally and running npm commands again worked for me
I had a ton of issues getting a very simple .NET Core 2.0 application to build in VS 2017. This is the error from AppVeyor, however it was essentially the same thing locally
(some paths omitted for security) :
Performing first-run Webpack build...
module.js:327
throw err;
EXEC : error : Cannot find module '......../node_modules/webpack/bin/webpack.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
csproj(25,5): error MSB3073: The command "node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" exited with code 1.
Build FAILED.
I stumbled upon this question and answer, and I noticed my local instance also had the same warning sign over the {Project Root} -> Dependencies -> npm folder. Right clicking and hitting "Restore packages" got everything loaded up properly, and I was able to build successfully.
npm link webpack
worked for me.
My webpack configuration:
"webpack": "^4.41.2",
"webpack-dev-server": "^3.9.0",
"webpack-cli": "^3.3.10"
For Visual Studio users: Right click on the npm folder and "Restore Packages".
While the suggested solution (npm link webpack) worked locally, on my CI (GitHub actions) I had the same problem, and to resolve it I used:
npm i --save-dev webpack
Laravel Users
If none of the above options work for you, then you probably need to install Laravel-mix correctly. Here is how:
npm install laravel-mix --save-dev
Now create a webpack.mix.js file using this command:
touch webpack.mix.js
Add this code into your webpack.mix.js file:
mix.js('resources/js/app.js', 'public/js').postCss('resources/css/app.css', 'public/css', [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
]);
You probably will also need to create a tailwind.config.js file using the command touch tailwind.config.js and then add this code ainto it:
module.exports = {
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('#tailwindcss/forms')],
};
Finally run npm run dev
So there are quite few possible issues, in my case on windows:
I moved my project to a folder with an & in the name, which is fine for windows but it break npm. My solution was to remove the & from the name.
test&mocking -> test_and_mocking
What solved it for me was that the path to webpack.config was wrong in build.js
rm -rf node_modules
rm -rf package.json-lock
npm install --force or npm install --legacy-peer-deps

Cannot run ionic. receives "No command 'ionic' found"

I want to start using the ionic framework, but unfortunately I'm already failing on the first step.
I am running Ubuntu 13.04 and I have node v0.10.25 installed.
I've installed ionic, at described in their docs:
sudo npm install -g cordova
sudo npm install -g ionic
The installation went well, no errors or warnings, but after the installation I type
ionic
and I get the error:
No command 'ionic' found, did you mean:
Command 'ionice' from package 'util-linux' (main)
Command 'sonic' from package 'sonic' (universe)
ionic: command not found
I'm pretty new to ubuntu so I might have something not configured correctly, but I can't find what.
Thanks
for some of you, the two answer above might not work. here's a more general solution for situation where you see "XX" command not found
first check your npm root and npm root -g
the result for the npm root -g should be something like "/usr/local".
if it's not, then you found your problem.
change it by:
npm config set prefix /usr/local
then npm root -g should give you something like /usr/local/lib/node_modules
.
Then go ahead re-install everything with -g
you will be good to go!
Well, I found it finally.
The ionic installation was at /home/guy/npm/bin/ionic, not at /usr/bin/ionic at it should be.
Solved it with:
sudo ln -s /home/guy/npm/bin/ionic /usr/bin/ionic
I solved the problem by cd to my root. Then install ionic as root admin.
$ sudo npm install -g cordova ionic
then run
$ ionic
to see if it's working.
Someone might run into this after trying to change the global library directory of npm to a folder they have permissions to write to in order to be able to install global libs without root permissions.
In that case you might have forgotten to add the new folder to you PATH environment variable.
The whole process of fixing Permissions can be found here.
in case that source disappears here is a copy of the steps:
There are times when you do not want to change ownership of the
default directory that npm uses (i.e. /usr) as this could cause some
problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory
altogether. In our case, this will be a hidden directory in our home folder.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4 you can also use the corresponding ENV variable (e.g. if you don't want to modify
~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global npm install -g jshint
if you just follow these steps and reinstall all the Global libs there is a good chance that it will start working for you anyways...
Just remember that if you do this, you will save your global libs into the folder created in step 1 instead of the default location in /usr/local or just /usr (depending on your OS flavor i guess?)
First Solution
I recently ran into this issue and the only solution that worked for me was to uninstall both ionic and cordova.
npm uninstall -g cordova
npm uninstall -g ionic
Then just reinstall
npm install -g cordova
npm install -g ionic
Second Solution
I ran into this issue again! This time check your environmental variables.
Run npm bin -g and check if the path returned is in your environmental variables. For me, it prompted that it was not found in the terminal output. I added that path to the environmental variables and restarted the terminal. From there everything started to work again. (source)
I had the same problem with “bash: ionic: command not found”,
then I added:
%USERPROFILE%\AppData\Roaming\npm
to my environment variable’s path, then I reinstalled ionic and cordova and it start working.
For Mac users
1. install the ionic
npm i -g #ionic/cli
2. check npm path
npm root -g
3. copy full path of ionic
Ex. /usr/local/Cellar/node/15.2.1/lib/node_modules/#ionic/cli/bin
4. open this file as administrator "/etc/paths" with nano or whatever editor
Ex. sudo nano /etc/paths
5. Add ionic bin file full path to file ends. And save file.
That's it.
Run npm root -g, copy the result path and add it to the paths file:
sudo nano /etc/paths
Restart your console and it will work.
this worked for me. try adding below to the ~/.bash_profile for mac OSX el capitan users:
NPM_PACKAGES="${HOME}/.npm-packages"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
then run source ~/.bash_profile to reload the profile in terminal.
additional info: node v4.3.1
In my case, I have just uninstalled ionic and then reinstalled it. And it is working fine now.
I also faced same problem but i solved i used following commands on terminal it worked
sudo npm uninstall ionic
then i used
sudo npm install -g cordova ionic#latest
and it worked fine it automatically installs best stabel version of cordova and latest stable version of ionic . for me it installed ionic 3.7.0
and cordova 7.0.1
you can change temporary :
npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm\node_modules2
Run your command to install your package .
open file explorer copy the link C:\Users[username]\AppData\Roaming\npm\node_modules
ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.
copy your package file CMD to parent folder "npm"
copy your package folder to parent folder "node_modules"
now run npm config set prefix C:\Users[username]\AppData\Roaming\npm
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm
now package working correctly with Command line
=> this method working with me When npm block in installation Package for IONIC installation and ReactNative and another package npm.
The package name has changed from ionic to #ionic/cli!
To update, run: npm uninstall -g ionic
Then run: npm i -g #ionic/cli

Resources