magento / m2-devtools

Helpful in-browser debugging/inspection tools for the Magento 2 Front-End
Open Software License 3.0
172 stars 48 forks source link

Javascript Bundling not working correctly with Amazon modules enabled #43

Closed dverkade closed 5 years ago

dverkade commented 5 years ago

This issue is a:

Environment

Question Answer
Magento version 2.3.0
Browser + version Chrome 71.0.3578.80
node.js version (node -v) v6.14.3
npm version (npm -v) 3.10.10

Description

With the Amazon modules enabled (Amazon_Payments, Amazon_Login & Amazon_Core) the bundled javascript throws an error. This can be fixed by disabling the Amazon modules in Magento and removing any the entries in the build.js file referencing Amazon.

Expected result:

Javascript bundeling should work correctly with Amazon modules enabled.

Screenshots

This is the first error thrown: image

This will result and the following additional errors: image

Once the Amazon modules are disabled first error is gone. Additional errors are also gone.

DrewML commented 5 years ago

Thanks Danny! Would you be able to deploy this broken build to somewhere publicly-accessible like in #44? Would make it a bit quicker to debug.

DrewML commented 5 years ago

Without running the code, I was able to spot at least 1 of the issues from the screenshot.

The Amazon_Payments module is loading uiRegistry using a synchronous require call:

var registry = require('uiRegistry');

if (registry.get('amazonPayment') !== undefined) {
    var amazonPayment = registry.get('amazonPayment');

    define([amazonPayment.widgetUrl], function () {
        'use strict';

        //after amazon widgets file as loaded

    });
}

Because of the sync usage of require, that module is going to blow up anytime its code executes before the code of the module that it is obtaining with require('dependency').

DrewML commented 5 years ago

I logged a bug with the Amazon module: https://github.com/amzn/amazon-payments-magento-2-plugin/issues/405

We should be able to hack around this for the time being without an upstream fix, though. Let me know if you have some time to chat it out on Slack.

dverkade commented 5 years ago

@DrewML thanks! Not really a bug in Magento but of this 3rd party integration of Amazon.

dverkade commented 5 years ago

As a workaround I removed all Amazon references from my build.js file, which resolves this issue.

DrewML commented 5 years ago

As a workaround I removed all Amazon references from my build.js file, which resolves this issue.

ah yeah, that works too! I'm going to leave this issue open until it's resolved in the Amazon Payments module, so others with the problem can find this easily. I might just bake in a config fix for Amazon Payments until then 🤔

DrewML commented 5 years ago

This was fixed in the upstream module https://github.com/amzn/amazon-payments-magento-2-plugin/pull/410