How to fix docker container running 'cannot find module' error? - javascript

I am new to docker and trying to move my MERRN stack application to AWS. I want to dockerize it before I move it. However, when I followed this online tutorial at Medium - Docker with MERN stack I get to the part with starting up my docker image with docker run -p 5000:5000 -d backend and I get an error in VS code. I am not sure what this error means but I theorize it has to do with my folder management.
I will attach a snippet of my folder structure as well as the docker file I used. So my main problem is I am trying to get everything setup but this issue is hindering my progress. So any help would be appreciated. Thanks
DockerFile:
FROM node:10.19.0
# Create app directory
WORKDIR /usr/src/app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
# Bundle app source
COPY . .
# Install app dependencies
RUN npm install
EXPOSE 5000
CMD [ "npm", "start" ]
Error:
> exodus#1.0.0 start /usr/src/app
> node server
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module './routes/api/Email'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/src/app/server.js:24:19)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! exodus#1.0.0 start: `node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the exodus#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! /root/.npm/_logs/2020-10-28T20_13_53_160Z-debug.log
Search...
Stick to bottom

Your Dockerfile seems ok and your project structure, too.
I assume that the docker image is faulty for some reason and missing the files.
Can you try to build the image again? Is the COPY step executed correctly?
// Make sure to execute this in the project root.
docker build -t backend .
If the error persists, log into the docker container using bash or sh and try to manually start the node server with npm start:
docker run -p 5000:5000 -d backend /bin/bash
or
docker run -p 5000:5000 -d backend /bin/sh
Logging into the docker container will also help to investigate if e.g. some files were not transferred.

Related

Node Modules Not Found, Using Ubuntu 20.04.5

I an a Windows 10 user who uses WSL. I was using Ubuntu 20.04.5 provided from the Microsoft Store and executing node commands with no issues. However, I attempted to update Ubuntu 20.04.5 to Ubuntu Jammy (22.x) and I found that it was generating some errors when I attempted to utilize nodejs after installing nodejs and npm.
I decided to go back to using Ubuntu 20.04.5, and after reinstalling nodejs and npm I am encountering the same issues I had on Jammy. When I try to run my plain JavaScript app using node, I am greeted with the following error.
So far, I have found nothing that has solved my problem.
I also tried restarting the terminal as well as my computer. I am continually met with an error indicating that it cannot find the modules I am looking for. Please note that I have not used yarn or curl for any downloads, and have only used apt install as well as npm install.
When I attempt to run my app.js file in the correct directory.
>> node app.js
noseinternal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'stream/promises'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/mnt/c/Users/.../group-project-1-group-6-15064/lib/weatherHandler.js:4:22)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
So far, the error seems to make sense. Even though I have a node_modules folder in the directory, it may not have the specific module it is trying to load.
So I then try to use the node install command to install all dependencies based on my package.json.
>> node install
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/mnt/c/Users/.../group-project-1-group-6-15064/install'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
This command worked perfectly before I reinstalled everything.
I also tried to add to the PATH in my .bashrc file to no avail. I'm sure it's something so simple and frustrating, but after over 30 hours of troubleshooting, I have yet to have any kind of breakthrough.
Possibly useful info:
>> which node
/usr/bin/node
>> node -v
V10.19.0
>> which npm
/usr/bin/npm
>> npm -v
6.14.4
>> sudo npm install --global --verbose nodejs
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli '/usr/bin/npm',
npm verb cli 'install',
npm verb cli '--global',
npm verb cli '--verbose',
npm verb cli 'nodejs' ]
npm info using npm#6.14.4
npm info using node#v10.19.0
...
npm verb unbuild rmStuff nodejs#0.0.0 from /usr/local/lib/node_modules
...
npm verb exit [ 0, true ]
stream/promises was added in Node 15: https://nodejs.org/api/stream.html#streams-promises-api.
You have to update your Node.js, for that please refer to: https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl
You may use nvm to install and manage Node versions
# Download curl CLI utility
sudo apt-get install curl
# download nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
command -v nvm
If that doesn't work refer to nvm's troubleshooting guide.
Once you setup nvm, you can run
nvm install 16 # For example to install Node.js v16
nvm use 16 # To enable it in your current terminal
After that, you may need to reinstall your packages to avoid any unwanted behavior, just delete node_modules in your current project and re-run npm install.

npm run build fails with "Error: custom keyword definition is invalid: data.errors should be boolean"

I'm seeing an error with npm when I try to build a VueJS application. I'm seeing this error inside of a build stage in GitLab CI. I haven't been able to find any mention of the error message. I have previously been able to run npm run build successfully and I haven't made any changes to the Vue application code, so I'm unsure what could be causing this error.
- Building for production...
ERROR Error: custom keyword definition is invalid: data.errors should be boolean
Error: custom keyword definition is invalid: data.errors should be boolean
at Ajv.addKeyword (/app/node_modules/ajv/lib/keyword.js:65:13)
at module.exports (/app/node_modules/ajv-errors/index.js:10:7)
at Object.<anonymous> (/app/node_modules/terser-webpack-plugin/node_modules/schema-utils/src/validateOptions.js:22:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! code#0.1.0 build: `vue-cli-service build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the code#0.1.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! /root/.npm/_logs/2019-02-09T22_32_54_384Z-debug.log
The command '/bin/sh -c npm run build' returned a non-zero code: 1
ERROR: Job failed: exit code 1
Here is what I have in my docker file that is used to build the Vue app:
# build stage
FROM node:10.14.2-jessie as build-stage
WORKDIR /app/
COPY frontend/package.json /app/
RUN npm cache verify
RUN npm install
COPY frontend /app/
RUN npm run build
https://github.com/webpack/webpack/issues/8768
If you use yarn
add below to package.json
"resolutions": {
"ajv": "6.8.1"
}
then run yarn install
if you use npm
npm uninstall ajv
npm install ajv#6.8.1
In the node-modules I renamed ajv folder to ajv1. Now I copied an older version of ajv folder into node-modules folder from some other installation. It worked.
Quick fix:
Go to the ajv dependency in your node_modules folder:
node_modules/ajv/lib/keyword.js
comment out the line 64 and 65 :
if (!validateDefinition(definition))
throw new Error('custom keyword definition is invalid: ' + this.errorsText(validateDefinition.errors));
and it should works without side effects.

What else do I need to try to resolve this npm start error?

I have tried to resolve this by reading other stack overflow entries before posting, but the same error message keeps showing up.
I am trying to run a Javascript program that integrates ReactJS. It worked for a while and every time I would type "npm start" it would automatically bring up the webpage template in the browser. Now it gives me the following error(s):
jMBP:project javen$ npm start
> react-box#0.1.0 start /Users/javen/Desktop/project
> node scripts/start.js
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module 'react-dev-utils/prompt'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/Users/sland/Desktop/project/scripts/start.js:20:14)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-box#0.1.0 start: `node scripts/start.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-box#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! /Users/javen/.npm/_logs/2018-09-27T01_24_06_237Z-debug.log
I have the following installed:
node -v: v10.9.0
npm -v: 6.4.1
I have tried the following:
npm install --save-dev react-dev-utils
npm install -g npm#latest
rm -rf node_modules
npm install //this threw a lot of errors
In the package.json file, for react-dev-utils it says, "react-dev-utils": "^5.0.2" Also, I do not know if this matters, but in the process of trying fixing this, a package-lock.json file has shown up in my project folder. The "prompt" var the error is referring to is the start.js folder: var prompt = require('react-dev-utils/prompt');
I have read that downgrading to an older version of node can sometimes work. If this is the case, which version is best, and how do I do this? Any advice appreciated.
I think npm install --save-dev react-dev-utils commands generally solves the issue. If not then updating your configs to match the latest create-react-app will fix this issue.

Issues deploying meteor app to modulus

Following something similar to this... http://stuart-85933.onmodulus.net/ and that exact one. Tried a bunch of things for an hour and I'm dying. Help please!
Thanks.
"Unable to connect to any application instances."
Here is my logs on modulus website
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ../../main
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs meteor-dev-bundle
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls meteor-dev-bundle
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /mnt/app/bundle/programs/server/npm-debug.log
Now using node v0.10.41 (npm v3.9.6)
Found package.json: ./bundle/programs/server/package.json
Running command: npm start
> meteor-dev-bundle#0.0.0 start /mnt/app/bundle/programs/server
> node ../../main
assert.js:93
throw new assert.AssertionError({
^
AssertionError: "undefined" === "function"
at wrapPathFunction (/mnt/app/bundle/programs/server/mini-files.js:77:10)
at Object.<anonymous> (/mnt/app/bundle/programs/server/mini-files.js:108:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/mnt/app/bundle/programs/server/boot.js:9:13)
at Module._compile (module.js:456:26)
npm ERR! Linux 3.13.0-92-generic
npm ERR! argv "node" "/mnt/app/.modulus/nvm/v0.10.41/bin/npm" "start"
npm ERR! node v0.10.41
npm ERR! npm v3.9.6
npm ERR! code ELIFECYCLE
npm ERR! meteor-dev-bundle#0.0.0 start: `node ../../main`
npm ERR! Exit status 8
Modulus is currently working on adding compatibility for some of the newer Meteor releases i.e. Meteor 1.4. More information about this error can be found in the issues noted below. You can see updates on this issue here:meteor github issue, meteor build runtime, demeteorizer github issue
Edit: There is a workaround if you are still having trouble, but it is a little lengthy. This workaround should work for any new version of Meteor that comes out, even versions that aren't working with the Meteor runtime yet.
Make sure the app runs locally
Install any unresolved modules
i.e. if you get this message when running locally:
Unable to resolve some modules:
XYZ ...
If you notice problems related to these missing modules, consider running:
meteor npm install --save XYZ
Run demeteorizer
$ npm install demeteorizer -g
$ demeteorizer
Change directory to .demeteorized/bundle/programs/server/
$ cd .demeteorized/bundle/programs/server/
Run npm install in that directory
$ npm install
Edit the package.json in that directory after running 'npm install' and specify the correct node engine: i.e. node 4.4.7
Change directory to root of the bundle
$ cd ../../
Make sure you are in the root of 'bundle,' and then zip the contents
$ pwd
/exampleDirectory/yourProject/.demeteorized/bundle
Zip contents of bundle
$ zip -r -X myProject.zip ./
Move that zip to the root of your project directory (or a non hidden folder)
Go to your project dashboard at my.modulus.io
a. Stop your project
b. Change runtime to node.js in the
'administration' panel
c. Confirm you have MONGO_URL and ROOT_URL
specified in environment variables
d. Go back to 'home' of project
dashboard, and upload / deploy the zip

Cannot find module 'mongodb/node_modules/bson'

These are the statments i got after running the grunt serve command from the directory sangam
C:\Users\Rohit\Documents\GitHub\sangam>grunt serve
Running "serve" task
Running "clean:server" (clean) task
Running "env:all" (env) task
Running "concurrent:server" (concurrent) task
Running "injector:scripts" (injector) task
Missing option `template`, using `dest` as template instead
Injecting js files (14 files)
>> Nothing changed
Running "injector:css" (injector) task
Missing option `template`, using `dest` as template instead
Injecting css files (5 files)
>> Nothing changed
Running "wiredep:target" (wiredep) task
Running "autoprefixer:dist" (autoprefixer) task
Running "express:dev" (express) task
Starting background Express server
Debugger listening on port 5858
module.js:327
throw err;
^
Error: Cannot find module 'mongodb/node_modules/bson'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\Rohit\Documents\GitHub\sangam\node_modules\mongoose\lib\drivers\node-mongodb-native\objectid.js:8:16)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
Running "wait" task
>> Waiting for server reload...
Done waiting!
Running "open:server" (open) task
Running "watch" task
Waiting...
after running grunt serve , I get that error
"cannot find module 'mongodb/node_modules/bson'" ,
the localhost page opens , but I get " cant reach this page" , please help me with this
As written in the github-issue try doing following steps:-
Make sure these two packages are at these versions
"mongodb": "^2.1.16",
"mongoose": "^4.4.12"
npm install -g node-gyp
cd /to/your/project-folder
rm -rf node_modules
npm install
Also try doing :-
do npm install inside node_modules/mongodb.
Hope this will help you.
Try changing mongoose 4.2.8 into to package.json and npm install again.
It worked for me locally as well as on heroku.
what i did
Just deleted node_modules folder and run
npm install
it worked fine.
definitely it's important to do a:
npm install -g node-gyp
cd /to/your/project-folder
rm -rf node_modules
npm install

Categories