Why is the main file of my published npm package not accesible? - node.js

I published this pacakge to npm (here's the GitHub repo) and, as you see, the main file in package.json is "men". It looks like I'm missing something because once I download it with npm i -g real-men and type men into the terminal (even after restarting the terminal and doing source /etc/environment ), I get a "men: command not found".
I see, for instance, that the "ng" executable for the Angular CLI has a link in the /bin node folder. Then I thought "hey, maybe I'm missing a step which copies a link to that folder", but I'm still confused and haven't found anything by googling it.
OS: Manjaro x64 (Illyria 18.0.0-rc)
Node: placed in user home folder (tar.gz extracted there, bin folder manually added to PATH)
npm -v: 6.4.1
node -v: v8.12.0
EDIT: I've marked as deprecated the package, by the time being
Solved
Solved by adding this to package.json:
"bin": {
"men": "./men"
}
My bad, I was not aware of this property and its uses.

Maybe try:
npm install
You might have updated the file, but never actually downloaded the dependencies.

Related

Why different version of NPM is being used?

It is my understanding that npm gets installed alongside node when I use the node installer in Windows 10, and will be located in "D:\Program Files (x86)\nodejs" (I installed the 32 bit version to my D drive, C is my primary OS drive).
However, "npm's globally installed packages (including, potentially, npm itself) are stored separately in a user-specific directory (which is currently C:\Users<username>\AppData\Roaming\npm)." - https://docs.npmjs.com/try-the-latest-stable-version-of-npm
Initially, after I first installed nodejs, my Roaming/npm folder was empty since I did not install any packages globally. Afterwards, I wanted to upgrade my npm so I ran the following command - "npm i -g npm". This added the following items to my Roaming/npm folder.
Roaming/npm
Now, when I run npm -v, the updated version is shown (7.24.2).
My questions are:
1.) Since I only updated the global ( -g ) installed one ( %appdata%\npm\ ), the npm in "D:\Program Files (x86)\nodejs" should remain as the old version right? (6.4.13).
2.) If so, why is the newer version being used, if (refer to below)
According to https://docs.npmjs.com/try-the-latest-stable-version-of-npm, "it will always use the version of npm installed with node instead of the version of npm you installed using npm -g install npm#." This does not seem like the case for me.
I did a "echo %PATH%" in cmd and I have confirmed that "D:\Program Files (x86)\nodejs" is indeed placed before "C:\Users<username>\AppData\Roaming\npm". So why is the newer version being used instead?
I tried to open cmd in "D:\Program Files (x86)\nodejs" and ran ".\npm.cmd -v" and it still gave me the same result which I was not expecting (7.24.2). I looked at the date modified for the nodejs folder and it does not seem like any changes were made.
Another thing I tried was logging in as a different user on my PC and running "npm -v", when I did that, it was showing the old version (which is what I expected since npm was only updated for my admin account, (admin\Appdata\Roaming\npm). So why is it that when I'm logged in as admin, it seems like the npm in "D:\Program Files (x86)\nodejs" is updated as well?
Any help to enhance/correct my understanding would be greatly appreciated, I am still quite new to npm and node.
Update: I am aware that nvm exists. This question is asking about the behaviour mentioned above.

Why is "npm install" looking for a file that doesn't exist (package.json) on a fresh NodeJS installation?

Hello, World!
I am having trouble getting NPM working.
First, I installed node.js from https://nodejs.org/en/download/ (the 64-bit .msi, on Windows 10, Version 10.0.18362 Build 18362). Node -v is 12.16.3.
Using Powershell, I navigated to the nodejs directory created in the install. Then I attempted npm install, which ultimately drew a series of errors beginning with "ENOENT: no such file or directory, open '...\nodejs\package.json' ".
The nodejs directory contains a file called "package-lock.json", but no "package.json".
Renaming the "-lock" file did not fix the error.
I've read on this site that Node came with NPM pre-installed. I can run npm -v without a problem ("6.14.4" returned) but trying npm start gives me the same error as npm install (cannot find package.json).
I have uninstalled Node & reinstalled twice, same problem.
Thoughts?
You should create a package.json file for every project using npm libraries, whether or not you are going to publish your code anywhere.
The easiest way is to run npm init and answer the questions, then npm will create the package.json file.
(Or take a look at the docs for other ways to run init, like npm init -y to just generate a plain package.json that you can manually edit.)
BTW, package-lock.json is a different kind of file that's generated to say which versions of each transitive dependency were installed. It doesn't have the same format as package.json; don't mix them.

Node MODULE_NOT_FOUND

I just upgraded to node version 9.0.0 and am now getting this error in the command line when trying to use npm install
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'internal/util/types'
I'm using:
OSX 10.10.5
Node version 9.0.0
NPM version 5.5.1
Extra information: I am also trying to do this with a Laravel 5.5 project. This is how I update my version of node: How do I update Node.js?
run
rm -rf /usr/local/lib/node_modules/npm
and then re-install Node.js will work in most cases
Leaving this here for anyone using the n nodejs version manager:
$ n 6.12.0 # Go back to a stable release
$ npm install -g npm#latest # Update npm to latest
$ n lts # Get 8.9.1
$ npm install #Should work now.
The MODULE_NOT_FOUND error seems to happen when changing between node versions and some files are possibly still being cached. I am not sure exactly but the above sequence of commands work for me.
When I first got this, I solved just running "npm install" again to make sure everything was installed.
I got similar error also on Windows 8 after I have just upgraded node js. First: how I ran into the issue then the solution that worked for me.
How I ran to the issue:
When I did npm --version and node --version I discovered that I wass running npm v3.x and node 5.x. So I went to nodejs.org site from where I downloaded node-v8.11.3-x64.msi. After installing the msi package I confirmed that my nodejs version was now v8.11.3 via node --version command.
Then, when I ran "npm install http-server" (w/o the quotes) that's when I got the issue:
npm ERR!
node v8.11.3
npm ERR! npm v3.5.3
npm ERR! code MODULE_NOT_FOUND
My resolution:
I did some research including on the internet and found out that the npm version pointed to in my path was the one in my roaming profile C:\Users[myname.hostname]\AppData\Roaming\npm. In other words, the npm being used is not the one in the updated package I have just installed which is located in C:\Program Files\nodejs.
The resolution was to delete npm and npm-cache in the roaming folder. Note, I used cygwin as I was not able to delete these folders via Windows cmd prompt. With cygwin, I navigated to
cd "C:\Users[myname.hostname]\AppData\Roaming"
Then I removed the aforementioned folders like so
rm -rf npm-cache
rm -rf npm
After that, I opened a new Windows cmd prompt and was able to now successfully install http-server like so:
npm install http-server
Hope this works for you.
For me it was package installation issue, so I just write,
npm i or npm install in the root of the application.
to open the terminal in the root of the application, if you're using VS-code right click on the package.json and click on Open in integrated terminal.
I founded this problem too, so I found that I have imported wrong module instead of express module I had imported router module after I had replaced this two my code work as well
If all the above solutions doesn’t work check for any blank spaces in your folder/file where you copied the path
Make sure you are inside the project folder.
Rename the folder "node_modules" to any other name (for example: node_modules_old).
Run command: "npm i" (the command will build new the folder node_modules).
Try running your program again.
If the problem is resolved and your program is running correct, delete the old folder node_modules.
If you are using libraries make sure to install everything with npm or yarn before starting. And in cases of you files if you are going to use them make sure to do the export.module thing everytime.
If you are working with Local modules then don't have node_modules. All things go well in a easy way.
But if you want to work with both local and node_modules then use
.mjs (extension) - For modules
.cjs (extension) - For common scripts which you want to run with node
in which you can use require statements like
var http = require('http');
var fs = require('fs');
but if using .js extension then use
import http from "http"
import fs from "fs"
And also your package.json for type
Haa well, I have spent two days on this and have done everything I can to fix this issue even tried resetting the system but none of them reloved the issue.
And accidentally found out what was causing this issue, it is because of & in my parent folder name. File hierarchy R&D>remix>blog, When I was trying to run the blog server it was throwing module not found, require stack error.
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
Solution: I have changed the parent folder name to RnD and it fixed the issue. If the file name contains any special characters(even parent folders) try updating it. In my case, it is &
The MODULE_NOT_FOUND error happened to me and even running npm install the error persisted.
Try to do this
For me, what worked was deleting the node_modules folder
rm -r -f node_modules/
After that, run the command to install the package.json dependencies
npm install
What happened to me was that when I ran npm install for the first time I had a very low internet connection and therefore I believe that the packages from package.json were not downloaded correctly and due to that the MODULE_NOT_FOUND error occurred. The funny thing is that just running the npm install command has no effect because it understands that the package is already there but it isn't. Similar as a corrupted data. In my case the npm update was without effect too.
If when you are using React And getting this error message. You can use this ,
NPM
npm install #reduxjs/toolkit
Yarn
yarn add #reduxjs/toolkit

NPM on Windows doesn't know the directory

I'm in a subfolder (D:\Alex\Desktop\Git\project), but even in that directory, running npm list says that there's no such project in D:\Alex\Desktop. I also can't install node_modules because none of the npm commands know the actual folder I'm in. I haven't run into this issue at all before, any ideas?
Suggested Info to Gather (and add to your post):
What version of Windows is installed (likely not the issue, but there are some known issues associated with Windows 7)?
What version of Node.js is installed (Use: node -v to check)?
What version of NPM is installed (Use: npm -v to check)?
When Node.js is installed using the Microsoft Windows installer package (.msi) download, NPM will also be installed, but the version lags behind the latest. So, for example, if you install the current LTS version of Node.js (6.11.3), NPM will be at version: 3.10.10, whereas the latest version of NPM is: 5.4.2.
Based upon your description of the problem, I am guessing that your version of Node.js is current (or fairly close), but that your version of NPM may be a bit out of date. Older versions of NPM would commonly generate a confusing and misleading error message associated with local modules that did not contain a package.json file; so running npm ls would produce error output similar to:
npm ERR! error in D:\Alex\Desktop\Git\project: ENOENT: no such file or directory
If I have guessed correctly, you should be able to resolve the problem by creating a package.json file in the D:\Alex\Desktop\Git\project directory using one of the following options:
Open a command prompt terminal window in the: D:\Alex\Desktop\Git\project directory/folder, run: npm init, and provide answers to the question prompts.
Open a command prompt terminal window in the: D:\Alex\Desktop\Git\project directory/folder and run: npm init --yes (which will suppress the prompts and apply default values).
Use a text editor to paste the following drop-in values into: D:\Alex\Desktop\Git\project\package.json, which declares the 2 required values: "name", "version", and includes a "description" because if there is no "description" field in the package.json, NPM uses the first line of the README.md or README (and your project may not include either):
{
"name": "my-desktop-git-project",
"version": "1.0.0",
"description": "Alex's Desktop Git Project"
}

npm comes with node now. What does this mean?

Node noob here.
I had previously installed both npm and node separately.
Apparently, npm comes with node now. (link)
To my newbie mind, this means my previous dual installation is old and ugly. 1 binary > 2 binaries. So i uninstalled both.
Then I installed the latest node following the procedure. (i am running eOS)
Terminal
user#box:-$ which node
/usr/bin/node
user#box:-$ node -v
v0.10.22
user#box:-$ which npm
user#box:-$ npm -v
bash: /usr/bin/npm: No such file or directory
I can always run:
curl https://npmjs.org/install.sh | sh
but that seems to indicate that npm is actually NOT included in node.
When they say they are included do they just mean the code is in the same repo, but the binaries are still different?
Final question I have /usr/bin/node as well as /usr/bin/nodejs
can i delete one of these? im not sure when/where i picked up a second copy.
Yes, the nodejs package includes both node and npm executables. The code for each has its own repo, but when packaged both are included.
npm source: https://github.com/isaacs/npm
node source: https://github.com/joyent/node
When you install that .deb file from the PPA, you should get both /usr/bin/nodejs and /usr/bin/npm and 2 symlinks at /usr/bin/node (which points to) /etc/alternatives/node (which points to /usr/bin/nodejs).
If any of this isn't true, your install didn't fully succeed, most likely due to conflicting files you left around from your manual install. I would suggest uninstalling the .deb then making sure there are no stale files left from your manual install and then installing again.
Only node.js packages comes with npm. so if you are installing using an .msi, .exe, .dmg .pkg, .deb or using a package installer like apt-get, yum or brew, then you'll have both node and npm.
However,npm is not part of the node core. if you are installing node and using a method where you are using ./configure or make install || make link, then npm will not be installed, and will need to be compiled using the same type of installation, and node will have to be placed on your path.
If you used git, or unzipped node and you can see a configure script, then you will also need to acquire npm.
I've had issues (mostly on Mac) with npm ending up in directories that aren't in the terminal PATH. If you can figure out where npm is located, you can just add it to your path with something like:
export PATH=$PATH:/path/to/npm
I think (I'm not on a mac so I can't check at the moment) that it sometimes gets put in /usr/local/share/. But at any rate, the problem is likely NOT that npm isn't installed, but that it's installed somewhere you're not expecting.
Few months ago i had started learning the react so all this stuff i needed to install my laptop that had the ubuntu operating system.
What i did -- First i installed the node and without knowing that it came up with the npm package. I installed the npm package again.. but there was no conflict at all.
But after exploring all these things that nodejs have npm package. So i uninstalled the npm package due to concern about memory usage..
And Now everything is working fine....

Resources