nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.47k stars 280 forks source link

ERROR - node:internal/modules/cjs/loader:936 throw err; #3709

Closed GabrielCHP closed 2 years ago

GabrielCHP commented 2 years ago

Version

No response

Platform

Windows Powershell

Subsystem

Powershell

What steps will reproduce the bug?

Downloading node.js > Opening the Windows Powershell > Selecting the Folder > node install. # Not working!

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

node:internal/modules/cjs/loader:936 throw err; ^

Error: Cannot find module 'C:__MACOSX\hashlips\install' ←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)←[39m ←[90m at Function.Module._load (node:internal/modules/cjs/loader:778:27)←[39m ←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m ←[90m at node:internal/main/run_main_module:17:47←[39m { code: ←[32m'MODULE_NOT_FOUND'←[39m, requireStack: [] }

Additional information

BUG

jonasnapoles commented 2 years ago

Hi @jonasnapoles , I meant, do you have a node_modules folder outside of your client and server folder?

It's working perfectly fine when i try running heroku local, Screenshot 2022-03-29 at 9 58 00 AM

and I'm able to deploy on heroku too after having a package.json outside of my client and server file: Screenshot 2022-03-29 at 9 59 39 AM

However it's still Application Error on Heroku even after it builds successfully. Do you have any idea why?

My error: node:internal/modules/cjs/loader:936 2022-03-29T01:47:57.534626+00:00 app[web.1]: throw err; 2022-03-29T01:47:57.534626+00:00 app[web.1]: ^ 2022-03-29T01:47:57.534627+00:00 app[web.1]: 2022-03-29T01:47:57.534627+00:00 app[web.1]: Error: Cannot find module '/app/index.js' 2022-03-29T01:47:57.534628+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) 2022-03-29T01:47:57.534630+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27) 2022-03-29T01:47:57.534630+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) 2022-03-29T01:47:57.534631+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 { 2022-03-29T01:47:57.534631+00:00 app[web.1]: code: 'MODULE_NOT_FOUND', 2022-03-29T01:47:57.534632+00:00 app[web.1]: requireStack: [] 2022-03-29T01:47:57.534632+00:00 app[web.1]: }

@celestinecyr

I have the node_modules

image

I never used Heroku before, therefore I removed node_modules folder completely then and I run npm install again. After that I run npm start which was working.

jonasnapoles commented 2 years ago

I hope I helped

jonasnapoles commented 2 years ago

SOLVED

yin130 commented 2 years ago

Fixed by deleting node_modules directory, yarn.lock, package-lock.json and then installing again.

PriapusZeGod commented 2 years ago

Hey, I solved this by using npm install axios --save in my terminal(I am using VSCode and I used the built-in terminal there), hope that solves your problems as well!

AviLevin commented 2 years ago

fixing project path like duplicates names in folders or keyboard symbols solv my same issue here

Rolarg29 commented 2 years ago

I have the same problem

In my exact same case the problem was that I wasn´t inside the EXACT directory of the file, but in a folder containing each project folder (/Projects)>(Projects/project1)> node myproject1.js I hope this helps :)

daryazata commented 2 years ago

@jonasnapoles how is it solved? For me still an issue

BugzTheBunny commented 2 years ago

Yo, Maybe it will help for some of you.

Here is what worked for me: So, my main folder was named incorrectly, i had some spaces and dots in the root folder name, so I removed them, and i restarted the VSCode.

After that, for some reason npm run build did work for me.

and my package.json:

{
  "name": "webpack-typescript",
  "version": "1.0.0",
  "description": "Webpack is a bundling tool, it helps with the workflow.\r It helps to take all of the code and source from your code, and create an optimazied version of it, that is ready for distrebution.",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "ts-loader": "^9.3.0",
    "typescript": "^4.6.4",
    "webpack": "^5.72.0",
    "webpack-cli": "^4.9.2"
  }
}
kalaiselvi-ui commented 2 years ago

Well it seems this method is not working even for you(Even I'm getting the same error).

We'll figure out something.

for me also not working kindly give suggestions

kalaiselvi-ui commented 2 years ago

SOLVED

how did you solved, i did everything deleted node modules and installed again still i am facing the issue kindly suggest me please

Hassan-abdellah commented 2 years ago

try deleting the node modules folder and move the whole project folder to another place in your system and run npm install

this method solved the problem for me

kalaiselvi-ui commented 2 years ago

I will try this one thanks for your suggestion

On Thu, 12 May, 2022, 10:05 pm Hassan Abdellah, @.***> wrote:

try deleting the node modules folder and move the whole project folder to another place in your system and run npm install

this method solved the problem for me

— Reply to this email directly, view it on GitHub https://github.com/nodejs/help/issues/3709#issuecomment-1125280788, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASI73XZVJJFJIIPZDWJ3BXDVJVB6DANCNFSM5M7JOBJA . You are receiving this because you commented.Message ID: @.***>

Leoporto07 commented 2 years ago

I thought I had the same problem... and only after drinking a cup of coffee I noticed my mistake: Instead of npm install I had typed node install... and of course no such module could be found. From the initial error description this looks very similar.

Man I just figure out the problem! Using your comment, it really worked for me, the issue is acctually in every new folder you creat, you have to "install" the module! So I had this problem whe changed my folder, so after I typed npm install all has been solved!

GabrielCHP commented 2 years ago

GUYS I FOUND THE SOLUTION! Please let the name of your PNG images short, with no SPACE OR CAPITALIZED LETTERS! Try using short names for accessories, body, or whatever you are doing on NFTs! Don't put any special character!

Harrilee commented 2 years ago

GUYS I FOUND THE SOLUTION! Please let the name of your PNG images short, with no SPACE OR CAPITALIZED LETTERS! Try using short names for accessories, body, or whatever you are doing on NFTs! Don't put any special character!

I don't think this is a solution though. A proper solution must specify what's the max length limit for all assets, and perhaps solve this error.

wadebooth commented 2 years ago

I'll comment my mistake with a fix hoping it will help someone. I was using nodemon incorrectly, i was calling it as "nodemon ." in my terminal, when I used "npx nodemon src/index.js" it worked. Hope that fixes a VS Code or two out there.

Harrilee commented 2 years ago

I found out that it is the problem of my node.js version. After a switch from 18.2.0 back to 10.24.1 the problem is solved.

marxGourav commented 2 years ago

Yeah I'm facing similar problem. image

Any solution(s) for this?

just check the path is correct in app.js

const date = require(___dirname + "/views/date.js"_);

Adrian-opo commented 2 years ago

Yeah I'm facing similar problem. image Any solution(s) for this?

just check the path is correct in app.js

const date = require(___dirname + "/views/date.js"_);

no meu caso o que resolveu foi ir para o diretório correto

marxGourav commented 2 years ago

Send me your error so know your problem more clearly

marxGourav commented 2 years ago

Check the dir. Name of respective ejsfile

marcuspassos013 commented 2 years ago

this error occurs when the server is started in folder outside the project

AndNijaz commented 2 years ago

I found what was problem for me. Actually my folder structure was going like this: Web Dev & Programming => Udemy ReacJS => -First React Big Project => senbonzakura-food

And this "&" in the "Web Dev & Progamming" was making the probelm.

kumarmeet commented 2 years ago

Just add "engines": { "node": "16.x", "npm": "6.x" },

it will work and runs correctly for nodejs REST apis

santii-ez commented 2 years ago

In my case i had enter to src folder from the terminal. It was bad standing.

sDuyToans commented 2 years ago

I fixed it in the suck ways. First off all i tried to delete modules and package-lock.json then npm i to reinstall it but not work. Second i make new forder then delete modules and package-lock.json and remove the remaining items to the new forder, after that npm i to reinstall it but still not work. Finnaly i kinda make 1 new file to test and the modules run on that but not run on the file i want so i do type ls on my cmd and copy the name of the file i want from cmd to run node filename.js again and IT WORK!!! i don't know that it really the point when copy the exact name from cdm but i hope this gonna help.

kanam9 commented 2 years ago

I found a solution (excuse my english) First, search WHERE is "yournamefile".js then in vs code console do: cd "the location of yournamefile.js" finally do: node "yournamefile".js Technically it's just the location of your file, if it isnt, this is the video that helped me: https://www.youtube.com/watch?v=2FJ7HjW8OjY

asserpc commented 2 years ago

Saludos la solución para mi fue eliminar la carpera node_modules, instalar lite-server, agregar el cambio en el json, y agregar un commit. luego ya funciono todo ok

Liorrr commented 2 years ago

I was able to solve the issue for me. of course it won't help everyone since you may have other related issues causing this. the main issue I've had is that the node were looking for dependencies that I've removed from the project later on.

To solved the issue:

1. delete the following:

node_modules folder, and package-lock.json

Optional:

on a 2nd computer with similar issue it didn't worked without running: npm cache clean --force And restart of the IDE before running npm install

2. Than run:

npm install Now the node should start up without problems.

hope it helped some of you

rana0045 commented 2 years ago

npm audit fix --force

Shivam-Negi commented 2 years ago

npm install axios --save

broooooo it worked....... thankssssssssss

parthf commented 2 years ago

Yeah I'm facing similar problem. image

Any solution(s) for this?

majaliju commented 2 years ago

Yeah same here

Aksharmeet commented 2 years ago

I had the same issue but with yarn, so i deleted node modules, yarn.lock and .yarnrc and then ran yarn to install it all again. Now it's working like a charm

pbhDev commented 2 years ago

The error is explained here "Error: Cannot find module ... " It means in your app.js or server.js do not list modules you didn't install or use. If the error is about a file path, it just means the path is incorrect.

APACHE-0002 commented 2 years ago

O que resolveu pra mim: criei o script na package.json: "dev": "sucrase-node src/server.js" , e dei yarn dev, note que coloquei src/server.js, se eu colocasse somente server.js, ele nao encontraria o arquivo e dava o erro

ivan1016017 commented 2 years ago

I do not agree that this issue should be closed since there was not an accurate answer. I could find the answer to this issue. First you have to remember that you have npm and npx. In this case you have to use npx ts-node file_name.ts. Always keep in mind that Npm is a tool that is used to install packages. On the other hand, Npx is a tool that is used to execute packages.

MdodoIng commented 2 years ago

remove this line

mongoose.set('useFindAndModify', false);

LucianoSBja commented 2 years ago

The problem is that you are not in the correct folder to run the application or the script, you would have to open the terminal where it is located or search for it with VScode and try again

lucidethinker commented 2 years ago

Yeah I'm facing similar problem. image Any solution(s) for this?

just check the path is correct in app.js const date = require(___dirname + "/views/date.js"_);

no meu caso o que resolveu foi ir para o diretório correto

DO RESTART, it

Yeah I'm facing similar problem. image

Any solution(s) for this?

restart ur PC, it will work fine

gurucharansahay24 commented 2 years ago

I am also getting the same error so what to do . even i did again install npm but also got error.

node:internal/modules/cjs/loader:936 throw err; ^

Error: Cannot find module 'react-dev-utils/WatchMissingNodeModulesPlugin' Require stack:

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Gurucharan sahay\AppData\Roaming\npm-cache_logs\2022-08-24T09_35_13_075Z-debug.log

C:\Users\Gurucharan sahay\Downloads\Gurucharan (2)\mernProjectEcommerce-master\mernProjectEcommerce-master\frontend>

devvsakib commented 2 years ago

Thats not gonna work at all, try to recreate your app instead, lmao!!

igordavid19 commented 2 years ago

Olá! Verifica na sua pasta packjson se o caminho realmente está correto para iniciar, da um npm install -g nodemon. Deu certo aqui.

fausantosdev commented 2 years ago

GUYS I FOUND THE SOLUTION! Please let the name of your PNG images short, with no SPACE OR CAPITALIZED LETTERS! Try using short names for accessories, body, or whatever you are doing on NFTs! Don't put any special character!

I don't think this is a solution though. A proper solution must specify what's the max length limit for all assets, and perhaps solve this error.

THAT'S JUST THAT, PAY ATTENTION TO THE PATH NAME TO THE PROJECT, IF POSSIBLE DO NOT USE SPECIAL CHARACTERS OR BLANKS

MahmoudMardawi commented 2 years ago

@devvsakib oh my god! how to be smart like this! I can't imagin! waw incredible

devvsakib commented 2 years ago

thanku thanku🤣

narender56 commented 2 years ago

Deleting the project and re-installing worked for me. Just try if you didn't find any solutions 😅

devvsakib commented 2 years ago

Deleting the project and re-installing worked for me. Just try if you didn't find any solutions 😅

thats what i said, but no one care🤣this is the solution for this stupid prblem🤣

MahmoudMardawi commented 2 years ago

I deleted it again and again on linux and windows ... didn't not work besided I tried to manipulate the scripts in package.json also didn't work please check this link : https://github.com/wbkd/webpack-starter

this is the project for pluralsight course... educative