davideicardi / live-plugin-manager

Plugin manager and installer for Node.JS
MIT License
233 stars 44 forks source link

Regression in 0.15.1 (when used in browser context) #38

Closed strogonoff closed 2 years ago

strogonoff commented 4 years ago

I triple-checked and everything else left alone 0.15.1 results in an error while 0.15.0 works, so this must be a regression.

The error happens when plugin manager is used in browser context (Electron renderer) and is thrown by this specific line:

https://github.com/davideicardi/live-plugin-manager/blob/881a95c8a0b5d1895d0d7c32855f2914e9419e6b/src/PluginVm.ts#L438

I’ll try to copy the exact error later, it’s about console.Console either missing or not being a constructor.

For now downgraded to 0.15.0.

New user here, nice work!

davideicardi commented 4 years ago

Can you try to execute that on your environment?

console.Console({ stdout: process.stdout, stderr: process.stderr }); 

As described here: https://nodejs.org/docs/latest-v12.x/api/console.html#console_new_console_stdout_stderr_ignoreerrors

I suspect that console is not available in Electron or something similar. I'm not expert about Electron. Which node version are you using? Electron uses a built-in version?

thanks

strogonoff commented 4 years ago

I believe latest Electron bundles Node 12.16.3. Thanks, I’ll look into it

dianlight commented 3 years ago

The problem is the assumption that the current console object is the NodeJS object. For example if you use a log framework as electron-log the Console costructor don't exists.

A simple patch ( work in my case ) is:

@@ -435,7 +437,12 @@ export class PluginVm {
            sandbox.process = Object.create(srcGlobal.process || null);
        }
        if (!sandbox.console) {
-           sandbox.console = new console.Console({ stdout: process.stdout, stderr: process.stderr });
+           if(console.Console){
+               sandbox.console = new console.Console({ stdout: process.stdout, stderr: process.stderr });
+           } else {
+               const { Console } = require('console');
+               sandbox.console = new Console({ stdout: process.stdout, stderr: process.stderr });
+           }
        }

        // override the global obj to "unlink" it from the original global obj
davideicardi commented 3 years ago

Thanks @dianlight ! Do you want to create a PR?

davideicardi commented 3 years ago

It would be great to have some sort of unit test or example to reproduce this problem...

dianlight commented 3 years ago

@davideicardi now I don’t have much time. I will see what I can do.