OS: Windows 7 64-bit
Need to do parsing xml-file using Node.js.
Using a library for parsing xml2js.
Xml2js installed using the command "npm install xml2js".
However, if you run the code:
var fs = require ('fs'), xml2js = require ('xml2js');
var parser = new xml2js.Parser ();
fs.readFile ('<path to the xml-file>', function (err, data) {
parser.parseString (data, function (err, result) {
console.dir (result);
console.log ('Done');
});
});
an error:
module.js:340
throw err;
^
Error: Cannot find module 'xml2js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (<путь до js-файла>:3:14)
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 Function.Module.runMain (module.js:497:10)
Tell me, please, how to solve the problem?
I was also facing the same issue. Here's what I did:
Install the module using following:
$ npm install -g *module_name*
Then go to any parent dir of your project dir (it can be project dir itself) and run the following command:
$ npm link *module_name*
Make sure that the directory ./node_modules/xml2js exists.
When you run npm install somemodule at D:/test, it will be stored to D:/test/node_modules/somemodule, then you can require this module in D:/test/*.js, and you can not require it at D:/other/place/*.js. If you hope the module can be required anywhere you should run:
npm install somemodule -g
I had a similar issue and even tried the fix mentioned by Lellansin, but it didnt help. There were some issues with npm cache and I had to clear it using the command:
npm cache clean
And it worked for me.
Related
I recently updated my operating system, which is Pop-OS, which is a Ubuntu's distribution. Before updating, I could run nodejs with ZeroMQ perfectly. Now, I can't run any file with ZeroMQ, not even with just this SLOC-line: const zmq = require('zeromq')
I am using Visual Studio code and also I tried to uninstall and install from scratch nodejs and npm and nothing works.
This is the error:
myuser#pop-os:~/Documents/Lab/fuentes$ node publicadorServer.js
node:internal/modules/cjs/loader:922
throw err;
^
Error: Cannot find module '../build/Release/zmq.node'
Require stack:
- /home/myuser/node_modules/zeromq/lib/index.js
- /home/myuser/node_modules/zeromq/index.js
- /home/myuser/Documents/Lab/fuentes/publicadorServer.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:15)
at Function.Module._load (node:internal/modules/cjs/loader:763:27)
at Module.require (node:internal/modules/cjs/loader:991:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/home/myuser/node_modules/zeromq/lib/index.js:6:11)
at Module._compile (node:internal/modules/cjs/loader:1102:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
at Module.load (node:internal/modules/cjs/loader:967:32)
at Function.Module._load (node:internal/modules/cjs/loader:807:14)
at Module.require (node:internal/modules/cjs/loader:991:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/myuser/node_modules/zeromq/lib/index.js',
'/home/myuser/node_modules/zeromq/index.js',
'/home/myuser/Documents/Lab/fuentes/publicadorServer.js'
]
}
I have installed ZeroMQ with this command at the directory of the project : npm install zeromq#5
Any help would be appreciated.
Finally I could fix it, only with the command npm rebuild.
Unbelievable. I guess, installing a new version of node and the new operating system version make necessary to rebuild it, but I still don't understand that, if I uninstall nodejs and npm, why it was not working. Fortunately, it's all fixed.
I was using meteor 0.8.x but recently tried to upgrade to 0.9.2. It works locally but I'm not having any luck with meteor bundle or meteor build
First I got this error
/var/projects/myproject/live/bundle/programs/server/boot.js:198
}).run();
^
Error: /var/projects/myproject/live/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/build/Release/bcrypt_lib.node: invalid ELF header
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 bindings (/var/projects/myproject/live/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/node_modules/bindings/bindings.js:74:15)
at Object.<anonymous> (/var/projects/myproject/live/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/bcrypt.js:1:97)
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)
Things I've tried
Made sure live/bundle/programs/server/node_modules does not exist before starting.
ran npm install in live/bundle/programs/server as the README says to
Things I noticed. There's no bcrypt deps in live/bundle/programs/server/package.json. In 0.8.2 I had commands to install both fibers and bcrypt manually but apparently I don't need the fibers one anymore. It looks like I do need the bcrypt one but it's in a different location than it used to be.
I don't see anything in the docs about needing to go to /var/projects/myproject/live/bundle/programs/server/npm/npm-bcrypt and install bcrypt. I can manually delete it but am I doing something wrong?
Like I said I'm already installing it where 0.8.2 needed it in programs/server. Should I be manually installing in program/server/npm/npm-bcrypt? Should I add that to my list of places to ignore
I put that in just to try it and so now I get this error
/var/projects/myproject/live/bundle/programs/server/node_modules/fibers/future.js:173
throw(ex);
^
Error: Cannot find module 'websocket-driver'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/projects/myproject/live/bundle/programs/server/npm/ddp/node_modules/faye-websocket/lib/faye/websocket.js:8:14)
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)
Is that yet another module I need to manually install? I'm getting the impression I'm just doing something fundamentally wrong.
I've got the following meteor packages
.meteor/packages
# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
standard-app-packages
audit-argument-checks
iron:router#0.9.3
meteorhacks:npm#1.2.0
npm-container
packages.json
{
"semver": "2.3.1",
"winston": "0.7.3",
"winston-loggly": "1.0.1"
}
note: I'm developing/bundling on OSX but deploying on Ubuntu.
I had similar problems - I posted my solution over on DO
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-meteor-js-application-on-ubuntu-14-04-with-nginx?comment=19780
UPDATE - Here is the answer from that forum:
If anyone else has an issue like this with bcrypt - the app probably has its own copy in
/home/yourapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/
delete that noise. Then do this.
cd /home/yourapp/bundle/programs/server
npm install bcrypt
Then
cp -r /home/yourapp/bundle/programs/server/node_modules/bcrypt /home/yourapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/
then start your app and enjoy the meteory goodness.
On the general problem of . . .
(for those stumbling here via Google)
Cannot find module 'MODULE-NAME'
or
Can't find npm module 'MODULE-NAME'
If you've recently added or removed packages while the application is running, try stopping and restarting your meteor application.
// stop ( "CTRL+C" in terminal that launched process )
$ kill `ps ax | grep '[m]eteor' | awk '{print $1}'`
// start
$ meteor
I am new to node.js and stuck on the following. Any help will be appreciated:
I am running node.js (0.10.28) on ubuntu (12.10). The code I am working on is:
"use strict";
var mysql = require('node-mysql'),
connection = mysql.createConnection({
host: "127.0.0.1",
user: "user",
password: "password",
database: "dbname"
});
if(connection) {
console.log("Query");
connection.query("select * from client",function(err,res) {
if(err)console.log(err);
console.log(res);
});
}
I get the following error
Error: Cannot find module 'readable-stream'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/root/RonakNodeEmail/node_modules/node-mysql/lib/protocol/sequences/Query.js:7:20)
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)
I got this error for the a long while. Stupidly I hadn't installed gulp... In short this problem occurs when a package is missing.
npm install gulp -g
I would suggest working out which task you are running and then install that.
In my case, (windows)
after uninstalling nodejs, and before reinstalling it
I had to delete the folder:
C:\Program Files\nodejs\node_modules\npm
and after reinstalling node it worked like a sharm
There were many reason for this issue: I have faced this issue because I had older version of node.js related files.
Un-install the node.js
Go to your user folder like C:\Users\<uname> and find all the node.js related files and delete everything.
Install node.js freshly
It worked for me.
I was having this problem building a vue library. Deleting node_modules and re-running npm isntall and then rebuilding my lib worked.
After grepping I found:
$ cd /usr/lib/
$ ack-grep readable-stream
nodejs/sha/index.js
3:var Transform = require('stream').Transform || require('readable-stream').Transform
and change that line to:
var Transform = require('stream').Transform // || require('readable-stream').Transform
and error goes out!
-- System Information:
I wrote a small program using npm express. while I am running the program i am getting error like below.(I am new to node.js)
module.js:340
throw err;
^
Error: Cannot find module 'express'
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 Object.<anonymous> (C:\Users\node\node_modules\app.js:1:77)
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)
at Module.runMain (module.js:492:10)
Inside your app you obviously require the express module, probably like this:
var express = require('express');
For this line to work you need to install Express into the local context of your application. To do so run
$ npm install express
inside your application's folder. This will (if it does not yet exist) create a folder node_modules where all your dependencies go.
Additionally, I'd suggest that you put Express into your package.json inside the dependencies block, such as:
"dependencies": {
"express": "3.1.0"
}
Of course, you can adjust the version number to whatever version you use. Once you've done this for all of your dependencies, you can install them at once by simply running
$ npm install
That should fix it.
PS: It does not matter for this scenario whether you installed Express globally or not. A global installation is only good for having the express bootstrapper available system-wide. The require function always only searches within the local application context.
Error: Cannot find module '.-audio'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (F:\Stage_ete_2018_XperMedia\2eme stage\transcription-service-master\bin\lib\job.js:6:25)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
I already did :
npm install
npm install -audio
then after executing a google-cloud Error pop up and so on, if install one module the other pop up.
npm install -audio
This does nothing, it ignores non existing options that start with a -. NPM also does not give an error, as I tried with -something_that_does_exists_for_sure as an option.
I guess you want to install the audio package: https://github.com/audiojs/audio
npm install audio
+ audio#1.2.0
added 2 packages in 1.97s
It should read that it added two packages, I think you didnt install it yet.
Also I do not understand the .- in your error:
Error:Cannot find module '.-audio'
Below is how the code example looks like in the audio package readme. See it has no dots, nor minus symbols.
const Audio = require('audio')
Audio.load('./sample.mp3').then(audio =>
audio
.trim()
.normalize()
.fade(.5)
.fade(-.5)
.save('sample-edited.wav')
)
I guess you also need to remove those from your code. Dots are only needed if you want to require files from a certain directory, not for packages installed with NPM.
You can try with this once,
Remove node_modules folder from your project directory
npm install
npm install <your_package_name> --save