I'm trying to use Chroma library in Magento and so far I did the following two things:
- 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?
1 Answer 1
Try
var config = {
 paths: {
 "chroma": "js/chroma.min",
 "sampleJs": "js/_sample"
 },
 shim: {
 sampleJs: {
 deps: ['chroma']
 }
 }
};
- 
 No, same thing. I did setup:upgrade and Magento's seeing the changes. Still can't find that "variable".Захар Joe– Захар Joe2022年06月29日 20:14:03 +00:00Commented 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.Захар Joe– Захар Joe2022年06月29日 20:15:31 +00:00Commented Jun 29, 2022 at 20:15
- 
 do you have minification enabled? you may want to double-check your error console for 'chroma.min'MagePal Extensions– MagePal Extensions2022年06月29日 20:16:50 +00:00Commented 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.Захар Joe– Захар Joe2022年06月29日 20:19:33 +00:00Commented Jun 29, 2022 at 20:19
- 
 What mode is your Magento store in default, developer, or production?MagePal Extensions– MagePal Extensions2022年06月29日 20:30:23 +00:00Commented Jun 29, 2022 at 20:30
Explore related questions
See similar questions with these tags.