Why does NPM always throw an error, no matter what the command is? - npm

Whenever I type any NPM command, I get this error:
C:\Program Files (x86)\Microsoft Visual Studio 14.0>npm -v
internal/modules/cjs/loader.js:582
throw err;
^
Error: Cannot find module 'os-tmpdir'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (C:\Users\*I like my privacy*\AppData\Roaming\npm\node_modules\npm\node_modules\osenv\osenv.js:4:16)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
I've tried reinstalling node, but I keep getting that same error. I've noticed that if I search NPM in the "add or remove programs" page in settings, I get no results, if that's useful.
My version of Node is v10.13.0
I'm using Windows 10 Home, version 1803

I would remove node: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
And then reinstall it with NVM: https://github.com/creationix/nvm like this:
> nvm install 8.9.1
> nvm list // Will show you available NodeJS distribution
> 8.9.1
// So tell nvm to use your version
> nvm use 8.9.1
> nvm list
> * 8.9.1 (Currently using 64-bit executable)
> node -v
> 8.9.1

Related

Using npm to install puppetteer gives Error: Cannot find module 'puppeteer/internal/node/install.js'

Trying to install puppeteer on Centos 7
npm i puppeteer
> puppeteer#19.4.1 postinstall /mypath/node_modules/puppeteer
> node install.js
internal/modules/cjs/loader.js:775
throw err;
^
Error: Cannot find module 'puppeteer/internal/node/install.js'
Require stack:
- /mypath/node_modules/puppeteer/install.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
at Function.Module._load (internal/modules/cjs/loader.js:677:27)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/mypath/node_modules/puppeteer/install.js:38:27)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/mypath/node_modules/puppeteer/install.js'
]
}
It doesn't seem to have downloaded anything into the node_modules/ directory, which I think "npm i" should do, and all of the tutorials I have read do not ask you perform any action or download, before running the npm command.
What do I need to do, to make this install puppeteer? (with chrome)
I was getting this error because my node version was too old (version 10) but fixed it by switching to version 16.
To fix this I used nvm from the command line as follows:
nvm use 16
nvm alias default 16

Fresh install of gatsby fails with cannot find module 'detect-port'

So all I'm trying to do is install gatsby (first time on my system).
My operating system is: macOS 10.13.6
My first step was to make sure I have the right versions of node / npm:
nvm install 10
npm -v
6.14.4
node -v
v10.20.1
Then I simply tried to install gatsby cli:
npm install -g gatsby-cli
npm WARN deprecated core-js#2.6.11: core-js#<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js#3.
/Users/me/.nvm/versions/node/v10.20.1/bin/gatsby -> /Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/lib/index.js
> core-js#2.6.11 postinstall /Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock
Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
> gatsby-telemetry#1.3.8 postinstall /Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/node_modules/gatsby-telemetry
> node src/postinstall.js || true
> gatsby-cli#2.12.31 postinstall /Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli
> node scripts/postinstall.js
npm WARN acorn-dynamic-import#4.0.0 requires a peer of acorn#^6.0.0 but none is installed. You must install peer dependencies yourself.
+ gatsby-cli#2.12.31
added 670 packages from 470 contributors in 26.613s
Seems like it completed? Finally I tried to run something:
gatsby --help
/Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
throw ex;
^
Error: Cannot find module 'detect-port'
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:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/lib/recipes.js:18:42)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789: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)
Maybe something wrong with my setup? Thanks.
Here is the link to the current gitub issue: https://github.com/gatsbyjs/gatsby/issues/24325
Installing yarn and running yarn build or yarn develop is a workaround for the moment.

grpc error and npm error while starting blockchain app

I have installed all the prerequisites and i am getting following error while registering node admin after npm install. If anyone can please help me out with the error:-
hitesh#hitesh-VirtualBox:~/medication-blockchain/drug-app$ node registerAdmin.js
/home/hitesh/medication-blockchain/drug-app/node_modules/fabric-client/node_modules/grpc/src/grpc_extension.js:57
throw e;
^
Error: Cannot find module '/home/hitesh/medication-blockchain/drug-app/node_modules/fabric-client/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc/grpc_node.node'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/hitesh/medication-blockchain/drug-app/node_modules/fabric-client/node_modules/grpc/src/grpc_extension.js:32:13)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
Errors like the one in question most commonly show up because of installing gRPC on one platform/architecture/Node version, and then using it on a different one. This often comes up when loading an installed library into a docker image, or switching Node versions using nvm. In many cases, this can be resolved by running npm rebuild in the environment where the code will be run.
When u cloned sample, u also copied the node_modules, which doesn't work with ur pc parameters. First, delete the node_modules, reinstall with npm install -g (globally), restart the app, works fine.
Stop all running containers, and remove them:
$docker stop $(docker ps -a -q)
$docker rm $(docker ps -a -q)
Delete node_modules:
$cd medication-blockchain/drug-app/node_modules
Restart from scratch:
$cd medication-blockchain/drug-app
$./startFabric.sh
$npm install -g
$node registerAdmin.js
$node registerUser.js
$node server.js

Error: Cannot find module 'wrappy'

When I try to restore my packages via yarn I'm receiving the following error:
npm run yarn --ignore-platform --ignore-optional
...
error C:\Users\mdepouw\source\repos\MyRepo\node_modules\node-sass: Command failed.
Exit code: 1
Command: node scripts/install.js
Arguments:
Directory: C:\Users\mdepouw\source\repos\MyRepo\node_modules\node-sass
Output:
module.js:471
throw err;
^
Error: Cannot find module 'wrappy'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\mdepouw\source\repos\MyRepo\node_modules\inflight\inflight.js:1:76)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
When I a npm install it works fine.
Why does one work but not the other?
This usually happens when you update npm. To resolve this go to path "C:\Users[username]\AppData\Roaming" and delete "npm" and "npm-cache" folders. Then uninstall nodejs and reinstall using updated installer. This should solve your problem.

Assetic: Cannot find module 'less'

The problem:
I am using laravel 4 + basset for asset management (OSX).
i have added the twitter bootstrap to my composer as a dependency.
I want to compile the less files into a collection:
Basset::collection('TwitterBootstrap', function($collection)
{
// Collection definition.
$collection->add('../vendor/twbs/bootstrap/less/bootstrap.less');
})->apply('Less');
I then try to build the collection:
php artisan basset:build TwitterBootstrap
Which throws the error:
[Assetic\Exception\FilterException]
An error occurred while running:
'/usr/local/bin/node' '/private/var/folders/f4/xjby77695pbcgfdjfclfdqd40000gn/T/assetic_less5y7dnh'
Error Output:
module.js:340
throw err;
^
Error: Cannot find module 'less'
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)
at Object.<anonymous> (/private/var/folders/f4/xjby77695pbcgfdjfclfdqd40000gn/T/assetic_less5y7dnh:1:74)
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)
I have installed less globally - im unsure why this is throwing errors/what to fix (my path? a node config? an assetic config?)
I had the same problem and I solved it by installing less with npm :
npm install less
To use less globally, do not run "npm install less" at the root of your project.
Instead add a symlink to the global one (/home/{user}/node_modules/less/) in your project :
ln -s /home/{user}/node_modules/less/ /path/to/project/node_modules/less
ln -s /home/{user}/node_modules/less/bin/lessc /path/to/project/node_modules/less/.bin/lessc
How did you install less?
npm install less
Reference: https://npmjs.org/package/less
Edit... Just saw your footnote.
Another option would be to install lessPHP via composer and use LessphpFilter instead of LessFilter