Metro Has Encountered an error: Cannot read properties of undefined(reading 'transformfile'). ERROR - node.js

Not sure Why I am getting this issue. I am following a react-native tutorial, and am experiencing this error:
TransformFile(filePath, transformOptions) {
var _this3 = this;
return _asyncToGenerator(function*() {
// We need to be sure that the DependencyGraph has been initialized.
// TODO: Remove this ugly hack!
yield _this3._depGraphPromise;
return _this3._transformer.transformFile(filePath, transformOptions);
})();

This problem usually happens because the user is using a node version thats newer. You can solve this by downgrading your node using Nvm. Here is the Link to Using Nvm, https://www.npmjs.com/package/nvm. Let me know if you have any further questions :)

Related

How do you export an object in a module in nodejs?

There is something wrong with the way I understand how to use classes in a Javascript module and export them, or some bad assumption I made about how nodejs works. Please help me understand this better. I wanted to write a module that exposed an object that will "store things safely." I have a file ("safestore.js") with this in it:
class Safestore {
constructor() {
console.log("SUCCESS!");
}
... // I defined other methods here...
}
exports.safestore = Safestore; // I tried this with `new Safestore` and `new Safestore()` too.
I run nodejs on my command line and then:
> ss = require('./safestore');
{ safestore: [Function] }
> s = ss.safestore('pwd','./encFile.enc');
ReferenceError: Safestore is not defined...
Why is it telling me that Safestore is not defined while executing the safestore function which is defined in the same file where Safestore is, actually defined?
The question does not contain enough information, although there is a clue. node and nodejs are two different pieces of software, and I was using the wrong one. I also didn't specify what version of nodejs I ran from my command line. When I ran it with node (instead of nodejs) I got errors that made sense and I was able to fix them.
Thanks to #Ethicist for listing the version of Node he used, as this got me to double check all those things.
I just need to remember that node and nodejs each do different things. Further research shows me that nodejs is a symlink to version 8.10.0 of node.js, and node is a symlink to the version that I set with nvm. I solved the problem permanently for myself with sudo rm /user/bin/nodejs and I'll remember, if I ever see an error that says nodejs doesn't exist, that it wants the old version of node.js.

Tailing a file with node-tail in a Vue/Vite/Electron application

I'm want to play around with building desktop applications using Electron and Vue.
Now I got an idea where I want to tail a local .txt file using node-tail, and store these changes somewhere. I saw this app also doing this, so I thought I would be able to do something similar within a Vue/Electron app.
With everything installed and trying to run this code with yarn electron:dev:
import { Tail } from 'tail';
let tail = new Tail("C:/logs/somelog.txt");
tail.on("line", function(data) {
console.log(data);
});
tail.on("error", function(error) {
console.log('ERROR: ', error);
});
I get this error:
Uncaught TypeError: Class extends value undefined is not a constructor or null
I did some searching on the error, and most of the results said removing your node_modules folder and npm i again could help, but this didn't do the trick.
Also I saw someone comment that these problems might happen if you mix yarn and npm. Now I did install everything at first using yarn and then the node-tail package using npm. This person said the same about removing and installing again. But this doesn't work for me.

Firebase functions throws uncatchable error

I'm calling the following Firebase function:
exports.getUserRecord = functions.https.onCall(async (data, context) => {
try {
//This successfully logs an existing uid in firestore, it should be retrievable
console.log(context.auth.uid)
const doc = admin.firestore().collection('user').doc(context.auth.uid);
const res = await doc.get() //Isolated it down to this line that is failing
return res
} catch (err) {
console.log(err)
throw new functions.https.HttpsError('unavailable', 'some error message');
}
});
When calling this function I receive the following error on the client:
POST https://us-central1-xxx-xxx.cloudfunctions.net/getUserRecord 500
Uncaught (in promise) Error: INTERNAL
On the server logs I see this error:
Unhandled error function error(...args) {
write(entryFromArgs('ERROR', args));
}
I am wondering how there is an error that neither of my error logging lines are picking up, and also what is causing this error?
EDIT: I have also tried logging other things within my catch block but they do not appear, it seems there is an error but the code does not enter the catch block somehow.
I have also seen this post which seems to suggest this was an issue that was patched in firebase-functions 3.9.1, but I have upgraded and still have this issue
Walked through the firebase-functions code for onCall at v3.11.0 and I don't see any other issues that could relate to this in the code since the fix
https://github.com/firebase/firebase-functions/issues/757
After discussing with #Matt about node_module versions we found that the issue is related to node_modules not having updated to latest once the upgrade was initially done.
Notes for anyone running into this issue in the future
If updating to latest for this module make sure to do the following to cover all bases,
Look into node_modules/firebase-functions/package.json attribute version to make sure that the proper version is installed.
Also take a look at your root folder package.json and package-lock.json to makes sure the proper versions are the latest.
If anything is not at version v3.9.1 or higher, then do the following,
rm -rf node_modules
npm i firebase-functions#latest --save
After that, double check everything again to make sure all is good.

How to fix 'TypeError: Buffer.from is not a function'?

Problem
While trying to use ipfs-api in my application, I am getting below error:
ERROR TypeError: Buffer.from is not a function
at varintEncode (vendor.js:185602)
at Object../node_modules/is-ipfs/node_modules/multicodec/src/varint-table.js
.....
My typescript file
var ipfsAPI = require('ipfs-api');
....
ngOnInit() {
this.ipfsApi = ipfsAPI(this.globals.ipfsIp, '5001');
}
Reason
The files mentioned in the error statement use 'Buffer.from' internally.
Version Details
I read somewhere that it could be due to version issue and Buffer API is only available in Node v5.10.0+.
Buffer - 5.6.0 (latest)
Node - 10.17.0
ipfs-api - 26.1.2
So I don't think version is the issue in my case.
What I tried
To the files throwing error, I added:
const Buffer = require('buffer').Buffer
and the error moved on to next file, obviously this is not a solution and just a trial.
.
How to fix this issue? Any help would be appreciated.
I added this
const { Buffer } = require("node:buffer");
it seemed to work because the variable is now wrapped in curly braces.
previously I had this
const Buffer = require("node:buffer");
Looks like Buffer.from is added in Buffer v5.10.0 .
Try to update Node.js version to v10.20.1. It has Buffer.from function.

How to use tojocky/node-printer in meteorJS app

I am trying to use tojocky/node-printer library in meteorJS app.
I did following to install
meteor npm install --save node-printer
But when I try to use it, It doesnt seem to be working.
Following is my code snippet
import { printer } from 'node-printer';
import './mainLayout.html';
Template.mainLayout.helpers({
printers: function() {
return printer.getPrinters();
}
});
I get following error
Exception in template helper: TypeError: Cannot read property 'getPrinters' of undefined
What am I missing here? Any help would be appreciated.
I cant use this module.
Its server only.
It doesn't let you print from client browser.
Hope this helps anyone else trying to do this in future.

Resources