[question] Cannot read property 'indexOf' of undefined
Question
I found a previous result here: https://github.com/artf/grapesjs/issues/1772 however I can still not get it to work, using the most basic setup, as per your guide, and the answer given in that question.
My script:
<script>
jQuery(document).ready(function () {
grapesjs.init({
// Indicate where to init the editor. You can also pass an HTMLElement
container: '#gjs',
// Get the content for the canvas directly from the element
// As an alternative we could use: `components: '<h1>Hello World Component!</h1>'`,
components: '<h1>Hello World component!</h1>',
storageManager: {type: null}
});
});
</script>
and the page is simply:

which results in
jquery.js:3827 Uncaught TypeError: Cannot read property 'indexOf' of undefined
at grapes.js:6477
at prototype.js:884
at prototype.js:825
at Array.forEach (<anonymous>)
at Array.each (prototype.js:824)
at Array.findAll (prototype.js:883)
at unique (grapes.js:6476)
at Init.find (grapes.js:7188)
at child.render (grapes.js:48530)
at child.addToCollection (grapes.js:48734)
and no functionality.
Any help/advise?
Answers (3)
Any suggestions?
If you can't remove prototype from the project the only possible solution I see is to put the editor in an iframe
The same has been happening in my project as well, though I'm not using prototype.js, I hope there is a solution to this, any help would be appreciated!
Well @goprime10 if you're not using prototype.js I'd say it's another kind of issue, "Cannot read property 'indexOf' of undefined" means nothing without, at least, a stack trace. So if you need help, create a new issue, by following the template, please
Ok, so I figured out the issue is prototype.js! The project I am working on also loads prototype, and that is the root cause.
I have tried numerous ways to prevent this, as per https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/ however nothing shot of removing prototype.js from loading works. (which I cannot do)
Any suggestions?
The same has been happening in my project as well, though I'm not using prototype.js, I hope there is a solution to this, any help would be appreciated!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1053
[Question] Flag for preservation of unused styles
Hey @artf, is there any flag available to leave the unused styles? Referencing to you provided answer here. Thanks in advance and have a gr...
Issue #1106
traits setting not work after reload
Hello @artf previous issue Yes, you're right traits are there but you didn't read the my issues those I'm facing. 1. when you drag and drop...
Issue #792
Script property using function don't work with blocks
In Components & JS docs there's this example: This works perfectly. But I couldn't use a function instead of a string in script, as is said...
Issue #1214
Query for issue related to 873
Previous issue Please confirm, above reported bug has been resolved. Or still having same issue. Please confirm . Same issue with slider al...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.