davideicardi / live-plugin-manager

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

Plugin manager gives an error requiring aws-sdk #56

Open tyler-dunkel opened 3 years ago

tyler-dunkel commented 3 years ago

I am trying to install and require the aws-sdk package at runtime and am getting the following error

UnhandledPromiseRejectionWarning: TypeError: attachOn.addNamedListener is not a function

This error does not appear when installing the aws-sdk directly and importing it. I tried with several versions of the package with the same result.

Here is some simple code to test

import {PluginManager} from "live-plugin-manager";

async function test() {
  const pluginManager = new PluginManager({
    // pluginsPath: './plugins'
  })
  await pluginManager.install('aws-sdk')
  const aws = pluginManager.require('aws-sdk')

  console.log(aws)
}

test()
davideicardi commented 3 years ago

I can confirm that there are some problems, but not sure the root cause. AWS SDK is installed correctly but when I try to load it via require it throws the above exception.

It looks like something related some global object that it is not initialized as expected. I suspect that it is something related to how I initialize the VM object here. But for now I don't have much information ...

I will try to investigate in the future, but as usual any help is appreciated...

tyler-dunkel commented 3 years ago

I have started looking into this and have noticed where one of the changes is occurring. The file aws-sdk/lib/util.js has a function inherit. This function assigns an object to a constructor.prototype in this line features.constructor.prototype = newObject;. In both the live plugin manager AND as a regular dep, newObject is equal to Service {}. However, when I print out the result of features after the above line, things change.

When installing the aws-sdk as a regular dep:

FEATURES WITH CONSTURCTOR
{ constructor: [Function (anonymous)] }

When installing with live plugin manager:

FEATURES WITH CONSTURCTOR
{}

Do you have any idea on why this code would function differently in live plugin manager? I dont see any difference within the code itself.

davideicardi commented 3 years ago

Thank you @tyler-dunkel for your further investigation. I have tried to work on that issue in #63 . I should have fixed some errors, but aws-sdk still doesn't work ... I suspect that there is some other errors in that code, but for now I don't understand.

@tyler-dunkel @aacotroneo Can you try to help me by writing a unit test to reproduce the problem? See for example the following tests: https://github.com/davideicardi/live-plugin-manager/blob/46550cf0e02ad2f32a735111a7b995f4b06107f2/test/PluginManagerSuite.ts#L1275