Hi,
I have a little plugin and when trying to register it in my main.js via
PluginManager.register(‚MyPlugin‘, MyPlugin, ‚[data-my-plugin]‘);
like the documentation (Add Custom Javascript | Shopware Documentation) says I get an error that the plugin is already registered.
What I tried so far: I checked the PluginManager and found
- getPlugin(pluginName: String)
- getPluginList()
I tried to create a check if the plugin is already registred with both but failed in each case.
- getPlugin always throw in error in case the plugin had not been registered yet and the strict flag I found in some code sample wasn in my hosted 6.4.20 version anymore
- getPluginList returned undefined for MyPlugin but then complained it was already registred when using below code
if (!PluginManager.getPluginList()[‚MyPlugin‘]) {
console.log(PluginManager.getPluginList()[‚MyPlugin‘]);
PluginManager.register(‚MyPlugin‘, MyPlugin, ‚[data-my-plugin]‘);
}
Output was
undefined
all.js?1681754580919916:3 Uncaught Error: Plugin „MyPlugin“ is already registered.
at e.value (all.js?1681754580919916:3:25590)
at Function.value (all.js?1681754580919916:3:29360)
at Module.G7pA (all.js?1681754580919916:9:2807)
So I am kind of stuck how to prevent the error in a decent way unless I wanna use try catch which seems rather weird at this instance.
Actually I found this to be the case if I bundle the main.js via webpack. If I dont bundle. It seems Shopware does some magic and it works. After watching tutorial videos I had thought one needs to bundle the code?
Thanks
Tom