Canvas.script entries can not be JS modules
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Version 1.56.20 Chromium: 115.0.5790.171 (Offizieller Build) (arm64)
Reproducible demo link
none
Describe the bug
links entered into
let Editor = grapesjs.init({
canvas: {
scripts:[...],
...
can not refer to JavaScript modules, or you may run into the following error:
Uncaught SyntaxError: Cannot use import statement outside a module
This makes it really difficult to use modern JavaScript in combination with GrapesJS
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (3)
scripts: [
{ src: '...file.js', type: 'module' },
],
good to know, thanks
Thanks for reporting this, @rozek.
The error **error:
** occurs when Canvas attempts to access properties before the component lifecycle is fully initialized. This is a common race condition in GrapesJS.
**Immediate workaround:**
If you control the code, wrap calls with null-checks:
```javascript
if (component && typeof component.method === 'function') {
// your code
}
Root cause analysis: The Canvas doesn't validate state before invoking your method. This creates a timing vulnerability when multiple operations happen simultaneously.
Next steps:
- Try the null-guard workaround above
- Update to the latest GrapesJS ā many race conditions have been fixed
- If this persists, share your exact reproduction steps with the team
- Consider adding defensive checks in your own component initialization
This is actively being tracked and should be improved in upcoming releases.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5354
canvas.script entries do not respect an "import map"
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Version 1.56.20 Chromium: 115.0.5790.171 (Of...
Issue #5352
Uncaught SyntaxError: Unexpected token '{' at CanvasView.ts:590:12
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 1.56.20 Chromium: 115.0.5790.171 (...
Issue #5363
cannot "sort" elements of layer panel
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Version 1.56.20 Chromium: 115.0.5790.171 (Of...
Issue #5362
draggable/droppable property functions not called while dragging
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 1.56.20 Chromium: 115.0.5790.171 (...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins āPremium plugins ship with support, regular updates, and production-ready features ā save days of integration work.
Browse premium plugins āRelated tutorials
In-depth guides on the same topic.
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
GJS Market 2.0 - Donations, Tracking, Labels and Better Product Discovery
Weāve rolled out a new set of GrapesJS marketplace updates across GJS Market, focused on improving how creators distribute products
Tutorial
Preset DevFuture 2.0 ā New Update Released
Preset continues evolving as a clean, production-ready starting point for building visual editors powered by GrapesJS
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.