Node Modules Not Found, Using Ubuntu 20.04.5 - javascript

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.

Related

Cant see npm version on ubuntu because of Error: Cannot find module 'semver'

I reinstalled ubuntu on my machine and after that installed node, react, npm, when i tried to start old project and run into same error when i started the project but also when i tried to see version of npm.
node:internal/modules/cjs/loader:927
throw err;
^
Error: Cannot find module 'semver'
Require stack:
- /usr/share/npm/lib/utils/unsupported.js
- /usr/share/npm/bin/npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/usr/share/npm/lib/utils/unsupported.js:2:14)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/share/npm/lib/utils/unsupported.js',
'/usr/share/npm/bin/npm-cli.js'
]
}
I uninstalled and installed npm again but it didnt help
Try this link anotehr SO post
Basically what they are doing is the below steps:
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf ~/.npm
brew uninstall --force node
brew install node
replace brew with respective package manager
You generally don't need to install npm separately. npm is bundled with node and the version that is bundled will generally work with the version of node you are running. If you install npm separately, you run the risk of installing an incompatible version of node.
So uninstall npm. See if you still have an npm available. If not, uninstall and reinstall node. Do not install npm separately (unless it is using npm itself to update to a newer version of npm with npm install -g npm.)

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

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.

Cannot find module 'internal/fs' not working as per the existing solutions

I'm getting the following issue all the time while going to run my project. Even after downgraded my node version to 8.4.0 (npm version 5.3.0) still getting the same issue. I know there are so many solutions given like after removing the node_modules to run npm cache clean --force and then again npm install but this solution is not working as well.
PFB, the error:
npm start
m> subhojits-components#0.0.1 start
/home/subhojit/Desktop/my_project
> node server/index
Unspecified environment, booting dev server
Booting dev server....
module.js:491
throw err;
^
Error: Cannot find module 'internal/fs'
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at evalmachine.<anonymous>:40:20
at Object.<anonymous>
(/home/subhojit/Desktop/my_project/node_modules/express-
handlebars/node_modules/graceful-fs/fs.js:11:1)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! subhojits-components#0.0.1 start: `node server/index`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the subhojits-components#0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
Please let me know if there are anymore solutions. Any help would be appreciated.
Note: I'm using graceful-fs version 4.0.0
hi please import the graceful-fs library
like
import {userDefinedName} from 'graceful-fs';
hope it will help you.
or Click On the below Link.
graceful-fs
I have seen this error on external Apple engine.
Uninstalling the currently active version of node.js with nvm
So uninstall npm:
nvm deactivate
nvm uninstall <<version>>
Install stable version
nvm install <<version>>
nvm install 10.15.3
Install Angular/Cli (exemple)
npm install #angular/cli
npm link #angular/cli
Wish, it works.

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

Categories