Retrieving Node.js Module from GitHub - Error: ENOENT, open package/package.json' - node.js

To my understanding, the 'npm' knows about git, so i can use it to retrieve Node.js modules from github. So, I have created Node.js module and hosted it at github. When I try to install it in my Node.js project as following:
npm install git://github.com/git-user/repo.git
then i am getting following error:
Error: ENOENT, open '/Users/kapa/tmp/npm-12237/1371351143597-0.9469406655989587/package/package.json'
...
code ENOENT
npm ERR! errno 34
What am i doing wrong and how to install module from github? Thank You

Does your repository contain a proper package.json file? That is required to have your repository handled as an npm module.

You may be using a .zip file. NPM doesn't support it and it may throw an error. Here is what you can use: https://npmjs.org/doc/install.html#DESCRIPTION

For those who already have a package.json file:
Just in case you didn't notice the comments below the accepted answer, you need to make sure you are inside your app folder to be able to run npm start. It seems to be a common mistake to accidentally run npm start from one directory above. Hope this helps.

Related

npm start error caused by webpack version

I am having a problem when executing the command npm start on recently react apps. I don't have much experience with node.js and didn't find the exact problem on the internet so decided to ask here.
Two days ago I started having a problem that npm start didn't work in any react app I created, this morning I even created a new one with npx create-react-app test, opened the project folder in VSCode and immediately executed npm start but got the same problem so I don't think it is something I messed up in the other apps.
The error I get is this
> sci-cal#0.1.0 start C:\Users\virgi\OneDrive\Documentos\VS_VSC\typescript_vsc\test
> react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.44.2"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
C:\Users\virgi\node_modules\webpack (version: 5.52.1)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if C:\Users\virgi\node_modules\webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sci-cal#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sci-cal#0.1.0 start 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! C:\Users\virgi\AppData\Roaming\npm-cache\_logs\2021-09-16T11_48_33_404Z-debug.log
I already tried the first four steps but it didn't fix the issue and webpack is in the node_modules project folder.
I think that it may be an issue of the react version I am using not being updated and thus not recognizing webpack version 5.52.1 but as previously said, I don't have much experience with react and didn't find the exact same problem fix on the internet so I decided to ask here before doing anything else to prevent the problem from possibly getting worse.
Since you already tried the first 4 steps, you can try to browse to C:\Users\virgi and check if you have the node_modules folder here. Delete it and run npm start in your project again

Error: ENOENT: no such file or directory, stat 'C:\Users\username\Documents\My Music'

I am trying to run this react app: https://github.com/JackHeTech/multiplayer-chess-game
It works when I download the repo and do npm install and then npm start.
But when I try to make the project myself using create-react-app with these steps:
npx create-react-app frontend
*copy the required files from repo to frontend folder*
npm install <p1> <p2> ...
npm start
That doesn't work and shows these errors:
Compiling...
C:\Users\username\Documents\Projects\chess_server\frontend\node_modules\react-scripts\scripts\start.js:19
throw err;
^
[Error: ENOENT: no such file or directory, stat 'C:\Users\username\Documents\My Music'] {
errno: -4058,
code: 'ENOENT',
syscall: 'stat',
path: 'C:\\Users\\username\\Documents\\My Music'
}
PS C:\Users\username\Documents\Projects\chess_server\frontend>
Why is it pointing to 'C:\Users\username\Documents\My Music'? I have not used that path anywhere in my files.
Basically I am trying to recreate the project from the repo on my own. But it's giving me the error given above.
I ran into the same error, and the problem was that i was importing something without actually installing the npm package. In my case, it was react-router-dom. Double check that you've actually installed all your dependencies that you've used in your code with npm install --save <your dependency>
It is indeed odd that it references My music. Did try npm install inside the project folder? If so, try deleting package.json and running npm install again.
Edit: Also found this:
I was also plagued by this error, and after trying all the other answers, magically found the following solution:
Delete package-lock.json and the node_modules folder, then run npm install again.
If that doesn't work, try running these in order:
npm install
npm cache clean --force
npm install -g npm
npm install
and then re-deleting the above files and re-running npm install.
Worked for me!
Only do this when you don't see a build folder after pushing to GitHub again
it will work if you run: npm run build
-- This should create a build folder
Before you run: npm run deploy
Please remove the space between your folder name "My Music" to either "My_Music" or "My-Music" or "MyMusic" or whatever you like (but WITHOUT SPACE).
The issue here is as it detects space it will try to find path till My only and consider other members as attributes may be (I am not quite sure 😛)
It does not convert the path with encoding tahts the issue.
NOTE: Keep the practice to not add space in name of folder.

npm ERR! errno -13 when Installing npm module to windows 10 with wsl

I'm having an issue to install mongoose module to my project. I have already installed it globally and in other projects. But it is not installing in the current project.
I faced this issue many times. It sometimes installs the module without error and sometimes not.
I don't know what's the problem. It throws the "npm ERR! errno -13" error and says "The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user"
I have tried this npm command: "sudo npm I mongoose --save" with and without sudo. It throws same error. But it worked in the last project.
It also throws an error when I try to upgrade npm
Please help me to figure out the problem and solve it.
Check this out: https://hackersandslackers.com/fixing-your-npm-installation/
Why does this happen? Because by default, the post-install scripts attempt to run as the current user. Since the current user doesn't have permissions to mess with packages installed globally, the installation ultimately fails. To fix this, we need to reinstall Node the correct way.

Which file does npm look into when node.js global packages are being upgraded?

When I ran the command to update node.js global packages using npm update -g, I got the following error;
npm ERR! code ENOLOCAL
npm ERR! Could not install from "..\..\..\Dropbox\Inv\Programming\node.js\ibkr-api" as it does not contain a package.json file.
However, I found out that the folder "..\..\..\Dropbox\Inv\Programming\node.js\ibkr-api" no longer exists.
Which file does npm look into when global packages are being upgraded? Where is it located? I believe I can fix this error if I know where this file is located and modifying it.
I am using Windows 10, node.js v11.14.
Maybe the first answer to this question can help you find the files you are searching
Where does npm install packages?
When you located your npm\node_modules directory you should be able to find in it the folder "..\..\..\Dropbox\Inv\Programming\node.js\ibkr-api"and then modify it.

npm warnings about package.json

I am trying to follow socket.io simple chat tutorial using nodeJS:
socket.io chat with nodeJS
I only got to the place where you need to install express:
npm install --save express#4.15.2
and got these warnings:
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\James\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\James\package.json'
I did create the folder chat-example with package.json in it, as told in the tutorial.
Are these warnings due to the fact that nodeJS installs the 'express' package in a different location than my newly created chat-example folder with the package.json file so it doesn't find it?
I did install nodeJS a long time ago, and probably it now installs pacakges into a different location.
How can I delete the express I installed, and re-install it in the correct folder?
How do I see where nodeJS is currently installing packages and how can I change that?
Thanks
Every project based on Node and npm needs a package.json file in its root directory. You can create one with this command:
npm init
You can just hit enter for every question in the dialog that follows, don't worry, you can edit everything later.
After that, you can execute the install command to add express or any other package.

Resources