I'm new to Node.js and react-native. I followed the sample on send_telemetry.js exactly but when I run my react-native app I get an error: "The development server returned response error code 500.
the error message is:
bundling failed: Error: Unable to resolve module fs from ProjectPath\node_modules\azure-iot-device\lib\module_client.js: Module fs does not exist in the Haste module map";
Im running:
Node.js v10.15.3
NPM 6.4.1
react-native#0.59.2
First error was the same with Unable to resolve module events,
I can install events,
but the fs module is: "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it."
var Protocol = require('azure-iot-device-http').Http;
var DeviceClient = require('azure-iot-device').Client;
var Message = require('azure-iot-device').Message;
var connectionString = 'my connection string';
var client = DeviceClient.fromConnectionString(connectionString, Protocol);
function ConnectionTest(err) {
if (err) {
console.log('Could not connect: ' + err);
} else {
console.log('Client connected');
}
client.close(function () {
process.exit(0);
});
};
export async function Test() {
client.open(ConnectionTest);
};
Basically I need to know how to get the azure IOT hub client working in my react-native app (not using Expo).
Im pretty much stumped so any help would greatly be appreciated.
A dependency module is missing ... which is fs ...
this file-system npm module is incompatible with react-native ... cause it has it own different environment.
I had "import { symlink } from 'fs';" randomly pop up in one of my scripts. Once I deleted this line same issue you had went away. I would search your whole project for that line.
Related
I'm trying to port a nodejs MS SQL Server application to deno. I'm using the node compatibility library to allow the use of npm mssql package:
import { createRequire } from "https://deno.land/std/node/module.ts";
const require = createRequire(import.meta.url);
const sql = require('mssql')
async () => {
try {
await sql.connect('mssql://user:pwd#host/database')
const result = await sql.query`select * from the_table`
console.dir(result)
} catch (err) {
console.log('Error:', err)
}
}
However I'm getting an error:
error: Uncaught Error: Cannot find module 'crypto' Require stack:
C:\WORK\LEARN\DENO\node_modules\tedious\lib\connection.js
C:\WORK\LEARN\DENO\node_modules\tedious\lib\tedious.js
C:\WORK\LEARN\DENO\node_modules\mssql\lib\tedious.js
Note: upgrading to the latest version of mssql helped, getting a different error, 'unable to find module tty', which I think I can figure out.
The crypto library internal to Node is used internally by the mssql library, however this isn't fully ported to Deno yet as you can see here
https://deno.land/std#0.83.0/node
I am new to Node.js and I am trying to import module exports module.exports. But it does not give me any auto suggestions and displays a quick fix (an error) of that line.
logger.js
var url = 'https://www.google.com';
function log(message){
//send http request
console.log(message);
}
module.exports.log = log;
error.
var module: {
"d:/NotitiaZone/Node/logger": typeof import("d:/NotitiaZone/Node/logger");
}
File is a CommonJS module; it may be converted to an ES6 module.ts(80001)
my node version -v10.16.3 my npm versoin - 6.9.0
I have already installed below extensions.
I am trying to traverse through an array returned by fs library in my node.js application. In my local machine the following code is working fine:
var fs = require('fs');
var data = fs.readdirSync("<directory>");
if(data.includes('a')){
console.log('value found!');
}
But when I uploaded my same application in CloudFoundry, i got the error as:
Error: data.includes is not a function
can anyone explain what could be the reason for the same.
"Includes" doesn't work with Node 5.x So,please check node version.In order to make it work in current version.just follow below code.or you upgrade node to version 6.
if(data.indexOf('a')> -1){
console.log('value found!');
}
Can't add a database connection to my small react app, i tried a bunch of npm modules: sqlite, sqlite3, realm. All fall back with type error:
TypeError: stream is undefined
i do absolutely nothing, just added a require statement in my component case that error:
import db from 'sqlite';
or:
var sqlite = require('sqlite3').verbose();
The last trace string:
(function (process){
module.exports = function (blocking) {
[process.stdout, process.stderr].forEach(function (stream) {
if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function') {
stream._handle.setBlocking(blocking)
}
})
}
and real fails on building, with Error: Cannot find module 'AccessibilityInfo'
Your last trace points to the content of set-blocking npm module. Usually it is used by npmlog. It requires process.stderr and process.stdout to be present. In your case they aren't. If you are running the app in Electron that might be the case.
It probably means that you are attempting to run a nodejs library in the browser, and that will not work. You might be able to browserify the library.
I'm trying to download files to the filesystem in an electron app. My code, in the main thread, looks like this:
const dir = `${__dirname}/media`;
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const file = fs.createWriteStream(`${dir}/${name}`);
file.on("open", function() {
const request = http.get(url, function(response) {
response.pipe(file);
response.on('end', function() {
file.close();
...
});
});
request.on('error', function(err) {
...
});
});
This works when running in development using electron . But after I build it with electron-builder, I get the error in an alert:
Uncaught Exception:
Error: ENOENT, media/uploads_2016_02_BASF_Holistic_Program.jpg not found in /Users/nicholasstephan/Desktop/XXXXXXX/dist/Mac/XXXXXX.app/Contents/Resources/app.asar
at notFoundError (ELECTRON_ASAR.js:109:19)
at Object.module.(anonymous function) [as open] (ELECTRON_ASAR.js:209:16)
at WriteStream.open (fs.js:1890:6)
at new WriteStream (fs.js:1876:10)
at Object.fs.createWriteStream (fs.js:1831:10)
at next (/Users/nicholasstephan/Desktop/XXXXXXXX/dist/Mac/XXXXXXXX.app/Contents/Resources/app.asar/media.js:19:18)
at /Users/nicholasstephan/Desktop/XXXXXXXX/dist/Mac/XXXXXXXX.app/Contents/Resources/app.asar/media.js:52:4
...
where the media.js, ln 19, being referred to is the const file = fs.createWriteStream(${dir}/${name}); line in the code.
I've tried the solutions offered in about a dozen other similar stackoverflow answers, but none have fixed the problem.
What's going on here?
Thanks.
The built Electron app uses the Asar format. Asar is an archive format (it's really just one big file) though in Electron you are able to read from it as if it were a standard directory.
I presume (though I have not seen it explicitly documented) that it is not possible to write to an Asar with the fs functions. In any case there are almost certainly more appropriate locations to write data.
Try writing to a different path. Electron provides a number of useful paths using app.getPath(name) so you could for example write to the userData directory which holds configuration files for your app.