0

I'm trying to use Chroma library in Magento and so far I did the following two things:

  1. Created a app/design/frontend/Vendor/Theme/requirejs-config.js with the following content:
var config = {
deps: [
'js/chroma.min',
'js/_sample',
]
};

and a _sample.js file in app/design/frontend/Vendor/Theme/web/js/_sample.js with the following code:

chromaColor = chroma.random();

A pretty straightforward and simple thing to do, but in the browser while both scripts load just fine, _sample.js throws this error: Can't find variable: chroma.

Somehow my _sample.js just doesn't seem to have access to the Chroma library? Or is it something else? Am I including those files wrong?

asked Jun 29, 2022 at 18:54

1 Answer 1

0

Try

var config = {
 paths: {
 "chroma": "js/chroma.min",
 "sampleJs": "js/_sample"
 },
 shim: {
 sampleJs: {
 deps: ['chroma']
 }
 }
};
answered Jun 29, 2022 at 19:56
11
  • No, same thing. I did setup:upgrade and Magento's seeing the changes. Still can't find that "variable". Commented Jun 29, 2022 at 20:14
  • Wait, chroma.min isn't being loaded, at least I don't see it in the browser. _sample.js however does get loaded. Weird. Commented Jun 29, 2022 at 20:15
  • do you have minification enabled? you may want to double-check your error console for 'chroma.min' Commented Jun 29, 2022 at 20:16
  • Not sure about what you mean by "minification enabled", chroma itself is minified... But the console is totally silent about chroma.min.js, I've seen errors before that it can't load it for some reason (path wrong for example) but now it appears that it's not trying to load at all. It also stopped appearing in Sources (in Safari) that list all the js files for the page. Commented Jun 29, 2022 at 20:19
  • What mode is your Magento store in default, developer, or production? Commented Jun 29, 2022 at 20:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.