jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.68k stars 309 forks source link

Cannot initialize Custom Platform. The custom platform is not seen as extended class of Plugin #1555

Closed jBernavaPrah closed 1 year ago

jBernavaPrah commented 1 year ago

I'm submitting a...

I'm trying to implement a new Platform. You can reach the code here.

When I add the platform to the plugin side of the Jovo app, I start receiving this error:

TypeError: Cannot read properties of undefined (reading 'add')
    at App.use (/Users/jbernavaprah/WebstormProjects/personal/phoxal-ivr/node_modules/@jovotech/framework/src/App.ts:242:21)
    at new Extensible (/Users/jbernavaprah/WebstormProjects/personal/phoxal-ivr/node_modules/@jovotech/framework/src/Extensible.ts:39:12)
    at new App (/Users/jbernavaprah/WebstormProjects/personal/phoxal-ivr/node_modules/@jovotech/framework/src/App.ts:93:5)
    at Object.<anonymous> (/Users/jbernavaprah/WebstormProjects/personal/phoxal-ivr/src/app.ts:21:13)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)

Diggin in the Jovo framework code I found that this error is triggered for two main reasons. 1) My VonagePlatform is not seen as a class that extends Plugin. 2) the this.componentTree is not initialized yet in the code.

Now I'm stuck there because I cannot find what is missing on my Platform in order to be seen as Plugin.

Any help finding the bug is really appreciated!

FYI: I tried to add also different platforms (Alexa and Web), and both are seeing correctly as Plugin, so I'm sure is something related to my Platform.

Your Environment

jBernavaPrah commented 1 year ago

Closing because this is not an issue related to Jovo or my platform development.

Merely this is a knowing issue of javascript, if there are two instances of the same package (like class Plugin/Platform from @jovotech/framework) installed in both Jovo main app and in the ./node_modules of the development package, the VonagePlatform instanceof Plugin will return false because the Plugin class of the VonagePlatform is "different" from the one of the Jovo main app.

I'm still investigating how I can continue to develop using the local files, using the local path on package.json file: ... "dependencies": { "@jbernavaprah/jovo-vonage-platform": "file:../jovo-vonage-platform", ... }

In the main time, if I use the npm package, everything work as expected.

aswetlow commented 1 year ago

Hey @jBernavaPrah

"Yarn workspaces" works fine:

Let's assume you have this project structure:

/project/jovo-vonage-platform /project/jovo-app

Add this package.json in /project

{
  "private": true,
  "workspaces": ["jovo-vonage-platform"]
}

Add the platform dependency in your package.json in /project/jovo-app. Use the name of your package in /project/jovo-vonage-platform/package.json Example:

   "jovo-vonage-platform": "^4.5.5"

Run yarn install in /project

Run jovo run in /project/jovo-app