Module Not Found error after NPM Install - javascript

I'm new to Node and after successfully running NPM init for a node project, attempted to install lodash through:
npm install lodash --save
However, after running that command, I got the error:
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'internal/fs'
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/johnwolfe/.npm/_logs/2018-01-07T05_07_16_644Z-debug.log
I've also tried just running NPM install and I get the same error. What possible explanation is there for this error and how can I resolve it? I've tried other solutions on the web and nothing is working.
This is my package.json file:
{
"name": "notes",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Thank you for any insight!

Try the following ,
Delete all the dependencies of the project.
Reinstall.
rm -rf node_modules
npm install

I ended up having to do a deep uninstall of Node following this thread How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X) and then running Brew install Node again after resolving issues with symlinks.

I was trying to launch a React application using webpack.
I was getting module not found error even after installing it manually.error message even after installing the module
But "npm install" also gave below suggestion to run "npm audit fix"npm suggestion
I did "npm audit fix" as suggested.
It threw another error saying that existing version of another module does not meet the requirements of the latest version.
I had to install that version manually.
Then ran "npm audit fix" again and all the errors were resolved.

In my case, installation had issues as my intelliJ was not having enough permissions to create folders inside project workspace, following the below steps resolved my issue,
i) Ran my IntelliJ with administrator mode, but this was working for an instance after i restart i have to re-launch my IntelliJ again and this was an headache.
ii) Moved my workspace to path where IntelliJ has access to (earlier workspace was under users directory which was causing the permission issues).

Related

"npm ERR! invalid semver" while trying to publish npm package

npm ERR! code EBADSEMVER npm ERR! invalid semver: npm ERR! A complete log of this run can be found in:
I've already tried re-install node and semver. It doesn't works
without logs or package.json file I can only assume there's something wrong with version in your package.json file. Check if you have "version"in there that follows major.minor.patch mask:
{
"version": "0.0.1",
}
Or you trying to publish same version twice.
About semantic versioning npm

After I installed nodemon by "npm i nodemon" , when I tried to run it by "nodemon server.js" , it gives me this error. What should I do?

Screenshot form VS code terminalnodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the
path is correct and try again.
I just meet that question.
First, you should make sure that you had installed nodemon in a global way (npm install -g nodemon), and make sure global package dir is in the environment variables.
Secondly, you should RESTART VScode if you are opening it now.
I spent lots of time to make sure the previous one, but it still fails, then when I restart VScode, everything is fine!
Try to install nodemon globally:
https://github.com/remy/nodemon
npm install -g nodemon
and edit Your package.json for example like that:
"scripts": {
"start": "node server",
"dev": "nodemon server"
},
then in terminal enter the command =>
npm run dev
It should works for You now ;-)
Good Luck and Best regards !
Below are some solutions
This is how you can install nodemon
npm install -g nodemon
after that you have to run this command: npm run dev
here dev is (script) server name like
{
"main": "app.js",
"scripts": {
"dev": "nodemon app.js"
},
}
after that if you are facing error like
" 'nodemon' is not recognized as an internal or external command,
operable program or batch file. "
Then after install nodemon globally write below command:
npm config get prefix
in output you will get PATH and then past this path in to the Environment Variables and it solved
Restart the terminal and run this command
nodemon run dev
I hope after that it will work properly :)
I just had to use npx instead of npm
for e.g. - npx nodemon <server.js>

How do I manually change a file name in Parcel?

Every time I try to run npm start or npm build I get an error saying unknown: Entry /mnt/c/Users/kabre/Desktop/18-forkify/index.html does not exist. I got told that Parcel might be automatically renaming my index.html. Not sure how to go on about fixing this since I'm just starting out learning Parcel/npm.
Try this:
Run npm init -y in your project
Install parcel in your project: npm install parcel-bundler --save-dev
Put this in your package.json:
"scripts": {
"start": "parcel ./index.html",
}
Run npm start after this.
And will running perfect.
Find more in https://parceljs.org/getting_started.html

Error while running "npm start": 'next' is not recognized as an internal or external command,

I am having this error while running "npm start" command on terminal as I am trying to build a cryptocurrency tracker using React.js
my package.json file
{
"name": "nextjs-crypto-api",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "11.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"webpack": "^5.51.1"
},
"devDependencies": {
"eslint": "7.32.0",
"eslint-config-next": "11.1.0"
},
"description": "This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).",
"main": "next.config.js",
"author": "",
"license": "ISC"
}
Error:-
'next' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nextjs-crypto-api#0.1.0 start: next start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nextjs-crypto-api#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\LENOVO\AppData\Roaming\npm-cache_logs\2021-08-20T16_58_19_379Z-debug.log
Please help me with this error
Please read your WARNING first
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
That means you are trying to run the project without installing the node_modules beforehand.
So, you should be doing - first
npm i
and then
npm start
Seems like the issue with modules. I am not sure but try deleting your package-lock.json file and node_modules folder and then try below commands:
npm cache clean --force
and then again run
npm i or npm install
Same issue here until I realized I had an outdated version of Node.js installed.
Make sure to install the latest version of Node.js, then delete both the node_modules folder and package-lock.json file in your project.
Reinstall the node_modules:
npm install
Then run it using:
npm run dev
The above command is different from npm start because you're using Next.js
You should check your dependencies thoroughly, as they are compatible depending on the version of "devDependencies" that is being used. If you are using an outdated version and wish to update to a recent version, it could be the possible cause of your error. Review your package.json file and verify the dependencies. It could be helpful to review your git log and then run
npm install
or
"npm i"
to ensure all dependencies are properly updated.
You can use the "git diff" command in the terminal to view the changes made to a specific file. For example, if you want to see the changes made to the file "example.txt", you can run the command
git diff package.json
Recently, I encountered this problem but I was able to resolve it by carefully reviewing my dependencies and checking which versions were being used. By comparing the versions in my package.json
Here I am showing you the solution that I could give to my project which presented a similar case.
I would recommend checking each of the dependencies necessary for your project.

I am getting 404 error while running "npm publish"

I am trying to publish a package to the npm registry. But when I hit the command npm publish I get this error.
npm WARN prepublish-on-install As of npm#5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.
> imojha#1.0.0 prepublish .
> npm run build
> imojha#1.0.0 build /home/suraj/Projects/bitandbang
> node build.js
npm notice
npm notice 📦 imojha#1.0.0
npm notice === Tarball Contents ===
npm notice 1.1kB LICENSE
npm notice 3.6kB bin/output
npm notice 233B bin/card.js
npm notice 996B package.json
npm notice 293B README.md
npm notice === Tarball Details ===
npm notice name: imojha
npm notice version: 1.0.0
npm notice package size: 2.3 kB
npm notice unpacked size: 6.2 kB
npm notice shasum: bb283ae5fe8aed311771f369866c13e24f1eb937
npm notice integrity: sha512-Nzc+Ysmf4RgSi[...]XoT+OGYHNHoSQ==
npm notice total files: 5
npm notice
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.registry.github.com/imojha
npm ERR! 404
npm ERR! 404 'imojha#1.0.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/suraj/.npm/_logs/2020-10-24T14_54_01_996Z-debug.log
I have successfully run npm login. Then I am executing npm publish.
I have cloned this repo from GitHub and publishing to the npm. It's actually about creating npx card of your own name, like npx username. I am doing the same.
I have tried giving it a different package-name but couldn't make it. So, Could someone please tell me what I am doing wrong? Here is the package.json file.
{
"name": "suraj-ojha",
"version": "1.0.0",
"description": "A personal card for Suraj Ojha (#suraj)",
"main": "/bin/card.js",
"bin": {
"bitandbang": "./bin/card.js"
},
"repository": {
"type": "git",
"url": "git#github.com:Suraez/npxcard.git"
},
"homepage": "https://bnb.im",
"scripts": {
"prepublish": "npm run build",
"build": "node build.js",
"dev": "npm run build && node ./bin/card.js",
"lint": "standard",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"card",
"npm",
"npm card",
"npx",
"npx card",
"business card"
],
"author": "suraj Ojha",
"license": "MIT",
"files": [
"bin/card.js",
"bin/output"
],
"devDependencies": {
"boxen": "^2.1.0",
"chalk": "^2.4.1",
"standard": "^12.0.1"
},
"bugs": {
"url": "https://github.com/bnb/bitandbang/issues"
},
"dependencies": {},
"publishConfig": {
"registry": "https://npm.registry.github.com/"
}
}
Update: I believe its caused from issues from the .npmrc in your home folder. Messing with the $HOME variable also seems to make it fail. Removing that file, and logging back into npm seems to fix the issue.
Beyond the answer though, Suraj Oberai your question is very well worded with all the necessary information, I don't think you deserve your downvotes.
I've published many npm packages, but this was the first time I had come across this issue myself. It was very strange as there was almost no difference between this one and previous packages I've published. I had to track down the issue by taking one of my working packages and (many useless publishes later) slowly convert it into my attempt that was causing the error, only to get to the point where literally nothing different between the projects. Nothing except the HOME Env variable of the shell.
This is definitely a bug with npm. It seems like the error above is the default error, so its possible my change might not solve this issue for you.
The publishConfig URL might be wrong.
Can you try adding the publishConfig option in package.json:
"publishConfig": {
"registry":"https://npm.pkg.github.com"
},
It worked for with this other registry (maybe they updated it?):
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
GitHub NPM registry is used for private packages. The package name has to be scoped. "name": "suraj-ojha" won't work for GitHub. It needs to be something like #suraj/ojha or #bnb/bitandbang (since that's your GitHub username and repo name).
If you don't intend to publish a private package and want to publish it to the public, remove the publishConfig section in package.json so npm publish uses the default public registry.

Categories

Resources