Skip to content

Core Colorpicker JS doesn't work with RequireJS #17008

@PivitParkour94

Description

@PivitParkour94

Preconditions

  1. Magento 2.2.x
  2. Mysql Ver 15.1 Distrib 10.2.15-MariaDB, for Linux (x86_64) using readline 5.1
  3. PHP 7.0.30
  4. RequireJS 2.1.11

Steps to reproduce

  1. Create a javascript file that requires the colorpicker used in the core (under the product attribute Visual Swatch in the admin panel)
// Vendor_Module/js/this/custom/file
require([
    'jquery',
    'jquery/colorpicker/js/colorpicker',
], function ($) {
    'use strict';
    // do anything, the damage is done
    console.log("required the colorpicker. Be free!");

Expected result

  1. Should see a message in the console that says "required the colorpicker. Be free!"
  2. Can then customise the colorpicker as you would please.

Actual result

  1. Console error "Uncaught Error: Mismatched anonymous define() module" talking about the colorpicker.

To solve it, simply add any random string ID to the definition of the colorpicker.
Example

// lib/web/jquery/colorpicker/js/colorpicker.js:10
define("mage/colorpicker", [
	"jquery",
], function ($) {

A quick workaround is to simply repackage the colorpicker into the module/theme you want to use, with it patched as described, but it would be awesome to have this patched in the core, with the correct naming convention etc.

Please let me know if any more details are required.

Metadata

Metadata

Assignees

Labels

Issue: Cannot ReproduceCannot reproduce the issue on the latest `2.4-develop` branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions