flex-plugin-builder icon indicating copy to clipboard operation
flex-plugin-builder copied to clipboard

[BUG] CLI fails if there's a package.json at the root

Open lucasmpr opened this issue 4 years ago • 5 comments

Description

We have a monorepo here with multiple plugins. I was trying to do better and create a top-level package.json and discovered the start multiple plugins command fails for some reason:

twilio flex:plugins:start --name plugin-sample -l debug

If I delete the topmost package.json everything works again.

Versions

package version
@twilio/plugin-flex 4.2.2
node 14.15.1

Steps to Reproduce

Please provide the steps to reproduce this bug:

  1. Create a folder
  2. Create a plugin inside the folder
  3. Create a random package.json inside the folder
  4. Try to run twilio flex:plugins:start --name plugin-livance-flex-authenticator -l debug
  5. Delete the package.json -> Everything works again.

Expected Behavior

My flex instance and multiple plugins load.

Additional Context

I get the following error when trying to load.

[DEBUG] Cannot read property '@twilio/flex-ui' of undefined
[DEBUG] TypeError: Cannot read property '@twilio/flex-ui' of undefined
    at Object.isPluginDir (C:\Users\lucas\.twilio-cli\node_modules\flex-dev-utils\dist\fs.js:768:44)
    at C:\Users\lucas\.twilio-cli\node_modules\flex-plugin-scripts\dist\scripts\pre-script-check.js:236:31
    at step (C:\Users\lucas\.twilio-cli\node_modules\flex-plugin-scripts\dist\scripts\pre-script-check.js:33:23)
    at Object.next (C:\Users\lucas\.twilio-cli\node_modules\flex-plugin-scripts\dist\scripts\pre-script-check.js:14:53)
    at C:\Users\lucas\.twilio-cli\node_modules\flex-plugin-scripts\dist\scripts\pre-script-check.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Users\lucas\.twilio-cli\node_modules\flex-plugin-scripts\dist\scripts\pre-script-check.js:4:12)
    at Object.preScriptCheck [as default] (C:\Users\lucas\.twilio-cli\node_modules\flex-plugin-scripts\dist\scripts\pre-script-check.js:225:12)
    at FlexPluginsStart.runScript (C:\Users\lucas\.twilio-cli\node_modules\@twilio-labs\plugin-flex\dist\sub-commands\flex-plugin.js:344:95)
    at FlexPluginsStart.checkPlugin (C:\Users\lucas\.twilio-cli\node_modules\@twilio-labs\plugin-flex\dist\commands\flex\plugins\start.js:109:20)

lucasmpr avatar Dec 15 '21 02:12 lucasmpr

@lucasmpr When you run the start command in a folder that has a package.json, the CLI assumes that you are running it in a local plugin directory and tries to load that plugin, which is the reason why you are seeing this error. This is expected behavior since the start command enables loading plugins in these ways

  1. When you run it in a local plugin directory, it automatically loads the plugin without you having to explicitly pass its name every time via the --name parameter.
  2. When you run it outside of a plugin directory, you can now use --name to pass in the names of the plugins you want to load.

rnairtwilio avatar Dec 15 '21 16:12 rnairtwilio

Sure, but as I specified a name, shouldn't it search there first?

lucasmpr avatar Dec 15 '21 17:12 lucasmpr

I agree with @lucasmpr, when a name is provided it should look for the name first. Or at least check if the name in the root is the same or not and then look for it in a sub directory.

armandabric avatar Jan 26 '22 11:01 armandabric

Using @twilio/plugin-flex v5.0.6 and this issue is still present. 😞

The irony of this is that Twilio is using a monorepo for this project, but their tool does not support monorepos.

morficus avatar May 09 '22 16:05 morficus

Hello Can Someone Help me i getting error while i hit the command "twilio flex:plugins:start" it's show an error, i can't understand the error...

image

pratikshah0 avatar Jun 16 '22 04:06 pratikshah0

Hi,

This is a long open item more than a year now, hence closing it. Feel free to reopen it if still required.

anjha91 avatar Oct 04 '23 08:10 anjha91