Giter VIP home page Giter VIP logo

Comments (7)

JKrupinski avatar JKrupinski commented on August 18, 2024 3

@krzksz FYI It doesn't work because select2 lib includes define( multiple times for example:
define(['jquery'], factory);

S2.requirejs = requirejs;S2.require = require;S2.define = define;
S2.define("almond", function(){});

here's the condition from magepack/lib/bundle.js

else if (!moduleContents.match(/define\s*\(\s*['"]/m)) {
    moduleContents = moduleContents.replace(
        /define\s*\(/m,
        `define('${moduleName}', `
    );
}

It will not work because it will catch define("almond"

Not sure how to fix it but maybe you can check if there is no . before define in this expression or just search for only first occurance of define

from magepack.

readio avatar readio commented on August 18, 2024 2

@orthener I discovered when bundling with Magepack the select2 module doesn't get a unique name so once part of the bundle file you get the anonymous mismatched error.

As a quick fix you can manually add a name to the select2.js which will then allow it to work correctly in the bundle, see below.

(function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define('**your_unque_name**', ['jquery'], factory); } else if (typeof module === 'object' && module.exports) {

from magepack.

orthener avatar orthener commented on August 18, 2024
# magepack.config.js. Autogenerated
module.exports = [
    {
        url: [],
        name: 'product',
        modules: {
            ...
            'js/vendor/select2/select2.full.min': 'js/vendor/select2/select2.full.min',
            ...
        }
    },
]
# requirejs-config.js
var config = {
    map: {
        '*': {
        select2: 'js/vendor/select2/select2.full.min' // replace default select with full
    }
};

In magepack.config.js tried:

'select2': 'js/vendor/select2/select2.full.min',

Same result

from magepack.

gaiterjones avatar gaiterjones commented on August 18, 2024

Have you applied the "Refactor JavaScript mixins module" patch ?

from magepack.

readio avatar readio commented on August 18, 2024

I'm also seeing the same error with select2. I have the mixins patch applied.

This doesn't occur when bundling with Baler or DevTools/r.js.

from magepack.

orthener avatar orthener commented on August 18, 2024

Have you applied the "Refactor JavaScript mixins module" patch ?

Yes.

from magepack.

luksurious avatar luksurious commented on August 18, 2024

Stumbled upon this as well. Naming the define in the select2 code breaks the developer mode, when magepack is not active though, so we just went with removing it from the magepack bundle which is a fine workaround for the moment for us.

from magepack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.