Module.js failed to load server.js - javascript

I made a little project using node.js to do a few things with Discord. It worked when I ran it locally with node server.js and npm start. I decided to put my project online to see if a certain feature worked. When I uploaded it, the main javascript file (server.js) that starts everything wasn't found.
I just want to be clear that Module.js is not something I made, but part of the node.js built in modules. It's the thing that makes the require function what it is.
The error in all it's glory:
module.js:472
throw err;
^
Error: Cannot find module '/var/lib/openshift/583e028e2d52714d2500041/approot/runtime/repo/server.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:420:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:535:3
Package.json:
{
"name": "app",
"version": "0.0.1",
"description": "test",
"scripts": {
"start": "node --use_strict server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"main": "server.js",
"keywords": [
"discord",
],
"author": "kert",
"license": "ISC",
"dependencies": {
"express": "^4.14.0",
"discord.js": "7.0.0"
},
"engines" : {
"node" : "6.9.1"
}
}
Structure of files:
Discord
└─── .git
└─── node_modules
└─── rbservers <-nothing is used in this folder
└─── app.js
└─── package.json
└─── server.js
If anyone can point out what stupid thing I'm forgetting, pray tell.
My cartridge on OpenShift is the 'Node.js Auto-Updating' one.

Apparently, git wasn't staging/committing all the files in order for them to be pushed. I'll have to look around on how to fix this.
Ugh.

Related

Running nodemon causes "Error: Cannot find module" error, but is checking the wrong path?

I have a Node.js project where I'm using nodemon. I have a package.json script to start an Express server with nodemon, but when I run it I get an error that the module wasn't found. The package is definitely installed (I see it in /node_modules) but the error seems to be looking in the wrong directory?
package.json:
{
"name": "starter-weatherzen-back-end",
"version": "1.0.0",
"description": "Starter code for WeatherZen backend",
"main": "src/app.js",
"scripts": {
"start": "node src/server.js",
"start:dev": "nodemon src/server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"knex": "^0.21.12",
"pg": "^8.5.1"
},
"devDependencies": {
"nodemon": "^2.0.19"
}
}
Running "npm run start:dev" will throw an error:
Error: Cannot find module 'C:\Users\name\Desktop\Projects_SE\course\nodemon\bin\nodemon.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
The actual directory of the project is:
C:\Users\name\Desktop\Projects_SE\course\backend
with the module being installed in:
\backend\node_modules
Any help would be much appreciated.
Edit: Forgot to mention in case it's relevant, but running the normal start script (npm start) runs the server just fine.
Figured it out after reading elsewhere about potential issues with having a folder in your path with spaces in its name. Even though the folder isn't directly referenced anywhere in the code, I at one point renamed a folder to include a space. After getting rid of the space, nodemon is able to be found fine. Weirdly the folder wasn't even renamed back to its original name, still different, just without a space.

import React from 'react' SyntaxError: Unexpected identifier

My problem is that when I run "node index.js" I get this message:
Users/martina/JPMC-tech-task-2-PY3/index.js:1
import React from 'react';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:877:16)
at Module._compile (internal/modules/cjs/loader.js:928:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:994:10)
at Module.load (internal/modules/cjs/loader.js:813:32)
at Function.Module._load (internal/modules/cjs/loader.js:725:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1046:10)
at internal/main/run_main_module.js:17:11
this seems to say that there is a problem with the import on the first line of my index.js file, but i have no idea how to solve this problem. thank u if anyone can help!
my package.json :
{
"name": "jpmc-tech-task-2-py3",
"version": "1.0.0",
"description": "s",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "webpack-dev-server --config webpack.config.js"
},
"repository": {
"url": "git+https://github.com/insidesherpa/JPMC-tech-task-2-PY3.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/insidesherpa/JPMC-tech-task-2-PY3/issues"
},
"homepage": "https://github.com/insidesherpa/JPMC-tech-task-2-PY3#readme",
"type": "module"
}
basically what i'm being asked to do is that while having an http server on another terminal window i'm supposed to do "npm start" on this terminal and it should open a localhost web page with some data. (it's an assignment but i don't understand much of it) however npm start is not in my package.json by default and i saw that it seems to just be supposed to throw index.js, so that's what i'm trying to do but failing
Node doesn't support es6 import syntax, or didn't until recently.
I'm not exactly sure what your needs are, but here's some options:
Use a new version of node and .mjs. Check out this thread.
use require instead.
I've also had some success with the esm package.
Try running npm run start:dev
items in the script array of package.json are run by using the command npm run before the name of the script.

Error creating electron executable files for production

I'm new in Electron and the problem that I have is when I try to create an executable file.
I've tried many exemples and always I have the same problem. The executable file is created but when I try run it, don't work.
Appears the following error in a windows dialog
[Window Title] Error
[Main Instruction] A JavaScript error occurred in the main process
[Content] Uncaught Exception: Error: Unable to find a valid app
at Object. (D:\Projects\angular\my-electron-app\packages\my-electron-app-1.0.0-win32-ia32\resources\electron.asar\browser\init.js:121:9)
at Object. (D:\Projects\angular\my-electron-app\packages\my-electron-app-1.0.0-win32-ia32\resources\electron.asar\browser\init.js:188:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Function.Module.runMain (module.js:683:10)
at startup (bootstrap_node.js:196:16)
at bootstrap_node.js:622:3
[OK]
This is my package.json:
{
"name": "my-electron-app",
"version": "1.0.0",
"scripts": {
"start": "concurrently \"ng serve\" \"npm run electron\"",
"electron": "electron ./src/electron.dev",
"ng": "ng",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"package:win": "npm run build && cross-var electron-packager dist $npm_package_name-$npm_package_version --out=packages --platform=win32 --arch=all --overwrite "
...
}
How can I fixed this?
After studied a lot I found the solution, I don't know if it's the best way, but works.
When I was executing the build for my application, in my file "angular.json" had the property outputPath with this way: "outputPath": "dist/my-electron-app", but to generate my windows packge I needed only "dist".
In this way when I execute de command:
"package:win": "npm run build && cross-var electron-packager dist $npm_package_name-$npm_package_version --out=packages --platform=win32 --arch=all --overwrite "
it will generate only the folder "app" over my "electron\resources\" with the correct files, before that it generated the folder "app/my-app"
Thanks

Next.js: Module build failed: Error: Cannot find module 'react-hot-loader/babel' from '/home/ugurkaya/Desktop'

I am trying to get started with Next.js, yet I receive the following error:
Module build failed: Error: Cannot find module 'react-hot-loader/babel' from '/home/ugurkaya/Desktop'
The following is my package.json:
"name": "hello-next",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^6.0.4-canary.6",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-hot-loader": "next"
}
I added the react-hot-loader dependency manually when I get this error, yet it did not solve. Looking forward your helps!
I fixed this issue by just
npm install react-hot-loader --save-dev
This issue is generate because react not find react-hot-loader in dev dependancy
You can solve this problem you just need to install react-hot-loader as dev dependancy
npm install react-hot-loader --save-dev

Deploying Node/Express App to Heroku/Production -- Babel/ES6 Error

I'm having a lot of trouble deploying to heroku/production with babel(using babel-cli) + es6 javascript. My app is a simple express and node server written in es6 style javascript.
I'm using "babel-cli" (installed via package.json) and a postinstall script inside package.json to precompile my es6 javascript into a "build" folder before starting the server.
The weird thing is that everything compiles smoothly with babel-cli for development, but not for production.
When deploying to production/heroku, the build process gets stuck on the babel command in Makefile and throws an error.
Package.json
{
"name": "messenger-basic",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"clean": "rm -rf build && mkdir build",
"build-server": "babel src --out-dir build",
"build": "npm run clean && npm run build-server",
"postinstall": "make build",
"start": "node ./build/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-preset-es2015": "^6.9.0",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"request": "^2.72.0"
},
"engines": {
"node": "4.4.5"
},
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-preset-stage-2": "^6.11.0"
}
}
Makefile:
build: clean server_build
clean:
rm -rf build
mkdir -p build
server_build:
babel src --out-dir build
rsync -av --include \*/ --include \*.json --exclude \* ./src/ ./build/
rsync -av --include \*/ --include \*.ejs --exclude \* ./src/ ./build/
.PHONY: build clean
The error:
You have mistakenly installed the `babel` package, which is a no-op in Babel 6.
Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.
Any help would be much appreciated! Setting up server stuff is my worst nemesis! :(
I usually run babel through weback, so I could be wrong here (I don't typically use makefiles), BUT, I would assume you would need to install babel-core in order for it to run correctly? It seems like the error is related to the fact that you just have "babel" installed, which will not work with v6. You need to install its components, which at minimum would require "babel-core."

Categories

Resources