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

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.

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.

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.

When installed globally, my node app looks in the global node_modules folder

I'm making an app to generate a component structure for a client project. The app needs to be run from the command line and so I've made it a published npm app that can be installed globally, however when I run the app, it's ignoring the directory I'm trying to run it from and instead just looking in it's own node_modules directory (I've tried this under nvm and regularly installed node)
I'm trying to set the project root using the following: var projectRoot = path.dirname(require.main.filename)
I've also tried by using __dirname, which also failed to work.
The specific problem I'm trying to solve (although this is only the first of a few, all of which seem to be caused by the app looking in the wrong place) is that the app needs to find a config file before it will run. I've included the example code for this below:
fs.stat(path.join(projectRoot, '/clarity.yml'), function (err, stat) {
if (err === null) {
console.log(chalk.green('clarity.yml detected!\nLoading your preferences...\n\n'))
config = yml.safeLoad(fs.readFileSync(path.join(projectRoot, '/clarity.yml'), 'utf8'))
questionTime()
} else if (err.code === 'ENOENT') {
console.error(chalk.red('clarity.yml not found. Please add one to the root of your project. A template can be found at https://git.io/v5Tt2 \nProcess aborted with errors'))
process.exit(1)
}
})
The most annoying part is that when I made this about a year ago, it worked without issue, however, I was running node v4.4.5 then and now I am using v8.0.0 (I've also tried it on v6.0.0 and v7.0.0 with the same result).

'Cannot find module' error using karma-browserify on Windows

I'm attempting to set up unit testing on an Angular/Browserify project using Karma, Karma-Jasmine, and Karma-Browserify. I'm on a Windows machine, for reference. karma-cli is on my global npm path, and karma, karma-jasmine, karma-browserify, and browserify are all local npm installs, using -D.
I'm trying to pull in a single spec file, which looks like:
var PhoneListCtrl = require('../../../public/js/app/controllers/phone-list');
describe('PhoneListCtrl', function() {
var scope,
ctrl;
beforeEach(function() {
scope = {};
ctrl = new PhoneListCtrl(scope);
});
it('should create "phones" model with 3 phones', function() {
expect(scope).not.toBe(undefined);
});
});
And I get the following error every time:
Uncaught Error: Cannot find module 'Cc/gGH'
I get this exact same error after cloning the following repos, installing karma and all plugins, and attempting to run their example test suites:
https://github.com/xdissent/karma-browserify
https://github.com/waye929/angular-browserify
What on earth am I doing wrong? The test spec module is found correctly, and karma seems to be finding all necessary plugins/preprocessors, but it appears that karma-browserify is tripping on the require statement in a spec every time, for reasons I cannot fathom.
I've uninstalled and reinstalled karma and all related plugins numerous times now, to no avail.
I managed to find a solution. The issue was caused by karma-browserify's own module name hashing function, which is incompatible with newer versions of browserify. There's a fork that deals with it by using browserify's hashing function:
https://github.com/voidlock/karma-browserify/commit/3afe3b7485f2e4723bba5ad1c5a730d560b8c234
There's a pull request pending but in the meantime you can use the fork by placing
"karma-browserify": "https://github.com/voidlock/karma-browserify/tarball/use-browserify-hash-function"
in your package.json (dev)dependencies section.

Can I npm link on a nodejitsu instance?

I'm trying to use a lib that I need to install and then link with npm. I don't see any clear path for me to access my server this way using the jitsu cli. How would I go about doing this?
I work for nodejitsu.
First, I believe your problem can be solved by using bundledDependencies in your package.json like so:
{
"bundledDependencies": [ "myModule", "myFork" ]
}
Then, when jitsu bundles your app for deployment (which uses npm), it will also bundle your dependency with it.
If the package is on a personal fork of a project on github, npm also can pull directly from a git url. Check out http://npmjs.org/doc/ for more information on ways to pull npm modules from non-registry sources.
Also: We have a dedicated support team which can be contacted either through support#nodejitsu.com or at #nodejitsu on irc.freenode.net .
Have you tried using npm programmatically? The docs give the following example:
var npm = require("npm")
npm.commands.install(["some", "args"], function (er, data) {
if (er) return commandFailed(er)
// command succeeded, and data might have some info
})
You can find the full docs here: https://github.com/isaacs/npm/blob/master/README.md
So in your case maybe you do: (in psuedo code)
npm.commands.install(['mylibarary'], function(er, data) {
if (er) { throw Error(); }
npm.commands.link( ... args ... function(er, data) {
... happy amazing awesome ...
});
});
You should also drop by the IRC room. The people there are very helpful.

Resources