Node.js Cannot Find Module error on npm start - node.js

I am getting an error like the below when I run npm start command to start the server for my first react project. I have tried uninstalling and reinstalling the node.js but did not work. How can I resolve this issue? I am including my package.json and my directory structure over here.
This is the error:
> reactproject1#1.0.0 start C:\Users\LENOVO\reactproject1
> node index.js
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module 'C:\Users\LENOVO\reactproject1\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactproject1#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactproject1#1.0.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\LENOVO\AppData\Roaming\npm-cache\_logs\2020-07-18T09_12_04_972Z-debug.log
This is my package.json file of my react project. I have edited it by adding "start":"node index.js".
{
"name": "reactproject1",
"version": "1.0.0",
"description": "restropart",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}
My Directory tree is as follows
-ReactProject
-node_modules
-public
-src
->index.js
-package.json
-package-lock.json
My index.js file resides inside the src folder. The node_modules, public, src, package.json and package-lock.json files are on the same line.

The start script refers to index.js, but you don't have such a file - it's under src/index.js. You could either move it to the project root, or update the start script accordingly:
"scripts": {
"start": "node src/index.js"
},

Related

Node.js.json failure

I am getting an error for the following package.json file.
If you already have a default version of it. I would be appreciated.
Thanks.
D:\Dev\survey-reactjs>npm run start
npm ERR! code EJSONPARSE
npm ERR! file D:\Dev\survey-reactjs\package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 288 while parsing '{
npm ERR! JSON.parse "name": "survey-reactjs",
npm ERR! JSON.parse "version'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Asus\AppData\Roaming\npm-cache\_logs\2020-07-16T23_48_39_175Z-debug.log
The updated version is below:
Edit:
D:\Dev\survey-reactjs>npm run start
> survey-reactjs#0.1.0 start D:\Dev\survey-reactjs
> node server.js
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module 'D:\Dev\survey-reactjs\server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! survey-reactjs#0.1.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the survey-reactjs#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\Asus\AppData\Roaming\npm-cache\_logs\2020-07-17T00_26_04_833Z-debug.log
Package.json file
{
"name": "survey-reactjs",
"version": "0.0.2",
"description": "",
"main": "''",
"scripts": {
"build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
"dev": "webpack-dev-server --progress --profile --colors --hot"
"start": "node ./scripts/start.js",
},
"dependencies": {
"json-loader": "^0.5.4",
"json5-loader": "^0.6.0",
"jsx-loader": "^0.13.2",
"node-libs-browser": "1.0.0",
"react": "15.0.1",
"react-dom": "15.0.1"
}
}
The updated version is below.
Edit :
{
"name": "survey-reactjs",
"scripts": {
"start": "node server.js"
},
"version": "0.1.0",
"private": true,
"dependencies": {
"cra-template": "1.0.3",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-scripts": "3.4.1"
}
}
I have installed over the scratch but gets different error this time.
This JSON contains two errors:
{
"name": "survey-reactjs",
"version": "0.0.2",
"description": "",
"main": "''",
"scripts": {
"build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
"dev": "webpack-dev-server --progress --profile --colors --hot"
"start": "node ./scripts/start.js",
},
"dependencies": {
"json-loader": "^0.5.4",
"json5-loader": "^0.6.0",
"jsx-loader": "^0.13.2",
"node-libs-browser": "1.0.0",
"react": "15.0.1",
"react-dom": "15.0.1"
}
}
It has a missing comma in one place and an extra comma in another place. It should be this:
{
"name": "survey-reactjs",
"version": "0.0.2",
"description": "",
"main": "''",
"scripts": {
"build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
"dev": "webpack-dev-server --progress --profile --colors --hot",
"start": "node ./scripts/start.js"
},
"dependencies": {
"json-loader": "^0.5.4",
"json5-loader": "^0.6.0",
"jsx-loader": "^0.13.2",
"node-libs-browser": "1.0.0",
"react": "15.0.1",
"react-dom": "15.0.1"
}
}
A comma was added at the end of the "dev" line and a comma was removed after the "start" line. In the future, you can check your own JSON here: https://jsonlint.com/
This is probably not error with your package.json, If it was no error with your package.json then on npm run start you would not be getting error of module not found, So the error is module not found ! now, which module?
Please look closely at the issue D:\Dev\survey-reactjs\server.js
Please check the following:
Do you have server.js file on the above path directory, if it is there then please do check if you have any package you have used but never installed it through npm install package name
2.if above solution do not give you good result I suggest you try building project from below steps:
Whenever starting a project :
Build your package.json from npm init
then start installing packages required through npm install
then put you server.js file at root directory only
Please note that: Nodejs considers all your installed packages and any of JS file that you write as a seprate module

npm ERR! code ELIFECYCLE is being displayed while running "npn start" on window command line for the following package.json file

I am learning full stack web development with Angular and new to web deployment.I am unable to guess the reason behind this npm ERR! code ELIFECYCLE; displayed while running "npn start" on window command line for the following package.json file. I am stuck here and not much help available on google or I am unable to search right answer because of lack of proper keyword required to search the answer.
{
"name": "confusion",
"version": "1.0.0",
"description": "This is a website for Ristorante Con Fusion",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm run watch:all",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
},
"author": "Imtiaz",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.3.0",
"node-sass": "^4.13.1",
"onchange": "^3.3.0",
"parallelshell": "^3.0.2"
},
"dependencies": {
"bootstrap": "^4.0.0",
"bootstrap-icons": "^1.0.0-alpha2",
"bootstrap-social": "^5.1.1",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"popper.js": "^1.12.9"
}
}
OutPut:
C:\Users\NEW WS-08\Bootstrap4\conFusion>npm start
> confusion#1.0.0 start C:\Users\NEW WS-08\Bootstrap4\conFusion
> npm run watch:all
> confusion#1.0.0 watch:all C:\Users\NEW WS-08\Bootstrap4\conFusion
> parallelshell "npm run watch:scss" "npm run lite"
child_process.js:422
throw new ERR_INVALID_ARG_TYPE('options.cwd', 'string', options.cwd);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "options.cwd" property must be of type str
ing. Received type function
←[90m at normalizeSpawnArguments (child_process.js:422:11)←[39m
←[90m at spawn (child_process.js:534:16)←[39m
at C:\Users\NEW WS-08\Bootstrap4\conFusion\node_modules\←[4mparallelshell←[2
4m\index.js:104:17
at Array.forEach (<anonymous>)
at Object.<anonymous> (C:\Users\NEW WS-08\Bootstrap4\conFusion\node_modules\
←[4mparallelshell←[24m\index.js:100:6)
←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10
)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m
←[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)←[39
m {
code: ←[32m'ERR_INVALID_ARG_TYPE'←[39m
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 watch:all: `parallelshell "npm run watch:scss" "npm run
lite"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 watch:all script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\NEW WS-08\AppData\Roaming\npm-cache\_logs\2020-03-26T08_26
_18_785Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 start: `npm run watch:all`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\NEW WS-08\AppData\Roaming\npm-cache\_logs\2020-03-26T08_26
_18_841Z-debug.log
This is a common issue can not be fixed using npm audit fix. All you can do is to copy the actual index.js file of parallelshell into your node_modules directory.
So to do it below are the instructions:
1. Go to https://raw.githubusercontent.com/darkguy2008/parallelshell/master/index.js
2. Copy the content here.
3. Now go to the directory of your project, it may be something like /project/node_modules/parallelshell/index.js
4. Inside the index.js replace the contents with the one you copied from the link in Step 1.
5. Save the file and exit.
Hope this fix will work for you.

Heroku npm start starts from different location

I have a fully functional NodeJs application with a submodule bundled inside it, so the submodule is the main application, and the other node project is built upon it.
I would like to run the submodule (the inner application) from the outer application. It might sound strange, but this is really what I would like to achieve.
It works fine when I run it in a local environment, but I can not make it work on Heroku.
Locally I run it with the command: heroku local web
My Procfile: web: npm run startwithouteslint
My outer package.json:
{
"name": "chatgine-pension",
"version": "1.0.0",
"description": "Chatgine-pension application",
"engines": {
"node": "10.x"
},
"main": "chatiety-engine/index.js",
"scripts": {
"startwithouteslint": "npm run startwithouteslint --prefix chatiety-engine",
"start": "eslint \"**/*.js\" && npm start --prefix chatiety-engine",
"test": "eslint \"**/*.js\" && mocha test --recursive --exit",
"coverage": "eslint \"**/*.js\" && nyc --reporter=text mocha test --recursive --exit"
},
"dependencies": {},
"devDependencies": {},
"repository": {},
"keywords": [],
"license": "custom"
}
My inner package.json (inside chatiety-engine folder):
{
"name": "chatiety-engine",
"version": "1.0.0",
"description": "Chatiety-engine application",
"engines": {
"node": "10.x"
},
"main": "index.js",
"scripts": {
"startwithouteslint": "node index.js",
"start": "eslint \"**/*.js\" && node index.js",
"test": "eslint \"**/*.js\" && mocha test --recursive --exit",
"coverage": "eslint \"**/*.js\" && nyc --reporter=text mocha test --recursive --exit"
},
"dependencies": {},
"devDependencies": {},
"repository": {},
"keywords": [],
"license": "custom"
}
Structure of the project:
The error message from Heroku:
2019-11-25T16:43:45.727225+00:00 heroku[web.1]: Starting process with command `npm run startwithouteslint`
2019-11-25T16:43:48.223968+00:00 app[web.1]:
2019-11-25T16:43:48.223991+00:00 app[web.1]: > chatgine-pension#1.0.0 startwithouteslint /app
2019-11-25T16:43:48.223993+00:00 app[web.1]: > npm run startwithouteslint --prefix chatiety-engine
2019-11-25T16:43:48.223995+00:00 app[web.1]:
2019-11-25T16:43:48.559728+00:00 app[web.1]: npm ERR! code ENOENT
2019-11-25T16:43:48.560276+00:00 app[web.1]: npm ERR! syscall open
2019-11-25T16:43:48.560632+00:00 app[web.1]: npm ERR! path /app/chatiety-engine/package.json
2019-11-25T16:43:48.563785+00:00 app[web.1]: npm ERR! errno -2
2019-11-25T16:43:48.563789+00:00 app[web.1]: npm ERR! enoent ENOENT: no such file or directory, open '/app/chatiety-engine/package.json'
2019-11-25T16:43:48.563792+00:00 app[web.1]: npm ERR! enoent This is related to npm not being able to find a file.
2019-11-25T16:43:48.563793+00:00 app[web.1]: npm ERR! enoent
2019-11-25T16:43:48.570839+00:00 app[web.1]:
2019-11-25T16:43:48.571073+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-25T16:43:48.571158+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-11-25T16_43_48_563Z-debug.log
2019-11-25T16:43:48.578800+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-25T16:43:48.579173+00:00 app[web.1]: npm ERR! errno 254
2019-11-25T16:43:48.580465+00:00 app[web.1]: npm ERR! chatgine-pension#1.0.0 startwithouteslint: `npm run startwithouteslint --prefix chatiety-engine`
2019-11-25T16:43:48.580626+00:00 app[web.1]: npm ERR! Exit status 254
2019-11-25T16:43:48.580875+00:00 app[web.1]: npm ERR!
2019-11-25T16:43:48.581043+00:00 app[web.1]: npm ERR! Failed at the chatgine-pension#1.0.0 startwithouteslint script.
2019-11-25T16:43:48.581209+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-11-25T16:43:48.587148+00:00 app[web.1]:
2019-11-25T16:43:48.587357+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-25T16:43:48.587493+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-11-25T16_43_48_581Z-debug.log
2019-11-25T16:43:48.666923+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-25T16:43:48.642599+00:00 heroku[web.1]: Process exited with status 254
It seems like Heroku appends the /app at the beginning of the path but I have no idea why, and where could I turn it off.
EDIT: I was able to list all the environment variables used by Heroku, and two of those are very likely to cause the problem:
PWD=/app
HOME=/app
So far so good, but I can not override these env. variables. Do you have any idea how could I achieve this?
Thanks for any help in advance!
I was having the same problem. Just realize that my code was crashing. You have to fix the bug on your code, then this message "npm run startwithouteslint" will disappear. You can run "npm run start" in your terminal and some clues of your errors it will be on the screen.

Why does npm run build for babel throw an error: "babel: src does not exist"

My folder is src and I've installed babel via the CLI, yet I'm still getting an error, "babel:
src does not exist"
Here's a quick recording of of my code: https://drive.google.com/file/d/1YgEnJE87c0mEnsefY1xU94cvUedBtGhK/view
See above what I've tried.
{
"name": "notes-app",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src -d lib"
},
"author": "Jono Suave",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.7.0",
"#babel/core": "^7.7.2"
}
}
app.js
import getNotes from "notes.js"
getNotes()
notes.js
let getNotes = function() {
console.log(`Put the time in baby!`)
}
module.exports = getNotes
I expected babel to run and compile my ES6 import code in app.js, but instead received following error in terminal:
babel:
src does not exist
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! notes-app#1.0.0 build: `babel src -d lib`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the notes-app#1.0.0 build 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! /Users/jonosuave/.npm/_logs/2019-11-07T01_56_26_260Z-debug.log
In experimental node, Babel isn't even required -- just need to use a .mjs extension to files instead of .js
See explanation with example: How can I use an es6 import in node?

Why does "npm start" give me error when i try run my app?

i dont understand why i got this error every
time when i try run "npm start".
> # start E:\ReactNative\navigation_app
> expo start
internal/modules/cjs/loader.js:895
throw err;
^
Error: Cannot find module 'C:\Users\Roei\AppData\Roaming\npm\node_modules\expo-cli\bin\expo.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15)
at Function.Module._load (internal/modules/cjs/loader.js:785:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1143:12)
at internal/main/run_main_module.js:16:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # start: `expo start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # 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\Roei\AppData\Roaming\npm-cache\_logs\2019-11-16T17_19_40_408Z-debug.log
this is my package.json and try
to figure out whats wrong there
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "^35.0.0",
"expo-font": "^7.0.0",
"react": "16.8.3",
"react-dom": "16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
"react-native-web": "^0.11.7"
},
"devDependencies": {
"babel-preset-expo": "^7.1.0"
},
"private": true
}
i would like to solve that issue and to understand whats worng .
You need to install expo-cli globally npm i -g expo-cli
you need to install Expo. Run an npm install or install expo globally
You don't have Expo-CLI installed globally, that is why you are getting the error at your local project. It needs Expo module to work, but can't find it. So run npm install -g expo-cli as it has been said, if it does not install paste the error code here.

Resources