I have never used node.js before, and I have been researching the answer to this question, but I have had no luck.
I am trying to allow the user to enter an input number (and honestly have no idea how to do this). Upon some research I tested a very simple input/output code:
var readline = require('readline-sync');
var term1 = readline.question("Please enter your first binary term: ");
console.log("your number : " + term1);
But when I try this I am getting the error:
module.js:550
throw err;
^
Error: Cannot find module 'readline-sync'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/<name>/eclipse-workspace/319/SE319Assignment4/binaryCalc.js:1:78)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
I was wondering if anyone can help me figure out why readline-sync cannot be read, or if there is a better way to write this simple input/output code in general! Thanks
if you don't have the dependency listed in your package.json file, try running this command from your cmd (cd into the directory where binaryCalc.js is located at):
npm install --save readline-sync
if you do have it in there, just try
npm install
Yes you should create a dependency first
So for that just open your folder where your js file is there through terminal. And just follow the following steps.
. npm init
. npm install readline-sync --save
and after this just try to run your code
It will definately not show any error
If you don't have the 'readline-sync' dependency listed in your package.json file, you can try installing it by running the following command from your terminal or command prompt (while in the directory where your project is located):
npm install readline-sync
Or
npm install -D readline-sync #types/readline-sync
Or install it manually
"readline-sync": "^1.4.9"
then run the following command
npm install
Related
We've got some error and we try to install optionator but nothing happened. We're using Linux
We're trying to npm i from package.json which include this dependencies
"optionalDependencies": {
"eslint-config-<name>": "github:<username>/<repo>"
}
then we tried to run npm i optionator but still get the same error
Error: Cannot find module 'optionator'
Require stack:
- /usr/share/nodejs/eslint/lib/options.js
- /usr/share/nodejs/eslint/lib/cli.js
- /usr/share/nodejs/eslint/bin/eslint.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
at Function.Module._load (internal/modules/cjs/loader.js:730:27)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/usr/share/nodejs/eslint/lib/options.js:12:20)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/share/nodejs/eslint/lib/options.js',
'/usr/share/nodejs/eslint/lib/cli.js',
'/usr/share/nodejs/eslint/bin/eslint.js'
Anyone who experienced this, please help us. Thanks
So if you have not done an npm init then that is the issue. npm init initializes the project and will add the node_modules folder to the working directory, this will set it up as a node project. Then to install a dependency just run a npm install <dependency> although I do recommend doing a --save afterwards as well as it just ensures that the package is put in your current directory
$ npm init
$ npm install optionator --save
npm-init | npm Docs
Nothing worked until when I initialized the project in a new directory and reinstalled all the dependent modules afresh.
Need to give full access to package-lock.json
If you are using linux do this
sudo eslint init
I have installed node.js. Node seems to be working properly, however, npm is not being found, as you can see below.
C:\Users\jpdrc>node -v
v6.5.0
C:\Users\jpdrc>node hello.js
node is installed!
C:\Users\jpdrc>npm -v
module.js:457
throw err;
^
Error: Cannot find module 'strip-ansi'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\jpdrc\AppData\Roaming\npm\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\string-width\index.js:2:17)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
I have tried multiple solutions as the ones presented:
1- Windows -installed node.js but npm not found
2- Installing Node.js (and npm) on Windows 10
I have no idea what to try next
Thanks for the assistance
Here are my variables under path
As suggested below I have used where npm
C:\Users\jpdrc>where npm
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
Steps for solving the above issue:
Check that you have added the path of node in environment variable "path"
If it is there then check that npm is there in the directory which you have added in the path.
If npm is there in the required folder then go to CMD and then go to directory where npm is installed and try to run the version command again. If still you are getting the same issue then there could be two possibilities:
a. Installation is incorrect, try installing again
b. There could be proxy issue due to which packages are not getting downloaded
There cannot be any other issue.
You should be able to run the npm -v in the git bash terminal window. If you don't even have the git-bash app, then download and install git on your Windows.
So i moved to the directory where the .js file is located and i opend it with node filename.js got nodejs and everything installed on the ubuntu VPS and i get error:
throw err;
^
Error: Cannot find module 'is-property'
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> (/var/www/bot/node_modules/steamcommunity-mobile-confirmations/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-object-property/index.js:1:80)
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)
at require (internal/module.js:12:17)
what is the problem? or m i trying to run this file completly wrong?
It looks like you need to install a dependency.
Try running the following command in your terminal
npm install is-property --save
If you're trying to run a script with a package.json file, that should define all the dependencies you need. All that's left to do is run npm install in the project directory.
If there's no package.json defining dependencies, you'll need to install each missing dependency. As you've found out, it'll throw a missing module error if they're missing. You might run into this issue multiple times if there are multiple missing modules. To remedy that, either dive into the code, and look for require('package-name') statements that don't reference a local path. (E.g. require('./package') is a local file, whereas require('package') will look for an npm installed module.) Alternatively, you can just keep trying to run it, and install each missing dependency manually until it stops spitting out errors.
I highly recommend creating a package.json if one doesn't exist yet. You can use npm init, and any installed packages should be automatically added to it. Then you can save additional packages to it using npm install package-name --save, or npm install package-name -S. That way, if you use the same code on another machine/in another directory, you don't have to copy over the node_modules folder, as you can specify which packages/versions you want and install them with a single npm install.
Additionally, you may wish to read up on what the package.json file is in relation to node.
NPM Docs on package.json
I am going to use the Ionic framework to work on hybrid app development, so I installed all the necessary dependencies (node.js, cordova, etc.) and followed their Getting started section. Step number 3 simply involves running the following command within the app directory:
> ionic platform add android
However midway during the execution I got the following error:
module.js:341
throw err;
^
Error: Cannot find module 'config-chain'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (C:\Users\james.bonello\AppData\Roaming\npm\node_modules\cordova\node_modules\npm\lib\config\core.js:2:10)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
I ran > npm update first and tried again to see if the update fixes any missing dependencies and such but the problem persisted.
So, as the error clearly states, the module 'config-chain' is missing so I next ran
> npm install config-chain
While that did install the module, the error somehow still persisted (identical to the previous one). I am not sure what to do next and I cannot understand why npm is not recognizing the 'config-chain' module now. Any ideas?
From what I can see, the missing package config-chain is a dependency of the global package cordova.
You should re-install cordova:
npm cache clean
npm uninstall cordova -g
npm install cordova -g
IF the problem persists, you have to manually install the package inside cordova's modules:
C:> cd Users\james.bonello\AppData\Roaming\npm\node_modules\cordova
C:> npm install config-chain
I did npm install and it worked .
After I switch from one node.js version to another with n module - https://github.com/visionmedia/n/, my npm is broken...
MacBook-Pro-Dmitri:~ dmitri$ npm --version
module.js:340
throw err;
^
Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at /usr/local/bin/npm:19:11
at Object.<anonymous> (/usr/local/bin/npm:87:3)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
then i'm installing npm again as it was adviced here - https://github.com/visionmedia/n/issues/101
curl https://npmjs.org/install.sh | sh
npm begins to work..
but then i do another switch for node version:
n 0.8.22
and npm now is broken again with the same error.
it's very annoying.. do I need to install npm manually after every version switch?!
Are there different global package repositories for different versions?
Perhaps either that package needs to be re-installed globally sudo npm install -g or the package manage cache cleaned sudo npm cache clean after switching version(s).
Node and npm should get bundled together these days, if you are a frequent version changer like me. You can try installing node with NVM
https://github.com/creationix/nvm
This will help you differentiate packages in different node versions. Just do a npm install after the switch.
PS: The current node version is quite stable right now. You can just use the current version instead of 0.8.22
You could try installing npmlog manually: npm install -g npmlog
I had the same problem and couldn’t find a solution.
It seems that n is less well maintained than nvm so I completely removed node following these steps and re-installed it using nvm.
(And node now includes npm)
I had same problem on windows. I uninstalled node, deleted everything from its install directory and re-installed. After restarting command line, I got npm working again.