Canvas.script entries do not respect an "import map"
https://github.com/GrapesJS/grapesjs/issues/5353#issuecomment-1704023749
Read full answer below ā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
scripts referenced by canvas.scripts
let Editor = grapesjs.init({
canvas: {
scripts:[...],
...
can not import third-party modules based on an "import map".
if the same module has to be used both by editor, preview and HTML export it may require the preparation of two different script versions - one for development (within GrapesJS) and another one for deployment - which should definitely be avoided
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (4)
have you tested them?
when trying
canvas: {
scripts:[ // scripts for the "iframe"
{ src:'/js/ImportMap.json', type:'importmap' },
{ src:'/js/common-applet-support.esm.js', type:'module' },
],
styles: [ // stylesheets for the "iframe"
'/css/common-applet-support.css',
],
},
in the current version of GrapesJS, I get the following (expanded) error message in the browser log:
FrameView.ts:310 External import maps are not yet supported.
Ā | c | @ | FrameView.ts:310
-- | -- | -- | --
Ā | o.onload | @ | FrameView.ts:326
Ā | o._renderFrames | @ | CanvasView.ts:616
Ā | o._onFramesUpdate | @ | CanvasView.ts:103
Ā | g | @ | backbone.js:337
Ā | h | @ | backbone.js:322
Ā | c | @ | backbone.js:110
Ā | a.trigger | @ | backbone.js:312
Ā | set | @ | backbone.js:529
Ā | e._pageUpdated | @ | Canvas.ts:55
Ā | g | @ | backbone.js:336
Ā | h | @ | backbone.js:322
Ā | c | @ | backbone.js:110
Ā | a.trigger | @ | backbone.js:312
Ā | o._onPageChange | @ | index.ts:152
Ā | _e | @ | _executeBound.js:8
Ā | (anonymous) | @ | bind.js:10
Ā | (anonymous) | @ | restArguments.js:16
Ā | g | @ | backbone.js:337
Ā | h | @ | backbone.js:322
Ā | c | @ | backbone.js:110
Ā | a.trigger | @ | backbone.js:312
Ā | set | @ | backbone.js:529
Ā | o.select | @ | index.ts:258
Ā | (anonymous) | @ | index.ts:128
Ā | g | @ | backbone.js:336
Ā | h | @ | backbone.js:322
Ā | c | @ | backbone.js:110
Ā | a.trigger | @ | backbone.js:312
Ā | reset | @ | backbone.js:965
Ā | o.loadProjectData | @ | Module.ts:164
Ā | o.load | @ | index.ts:286
Ā | (anonymous) | @ | Editor.ts:856
Ā | o.loadData | @ | Editor.ts:856
Ā | (anonymous) | @ | Editor.ts:837
Ā | (anonymous) | @ | grapes.min.js:2
Ā | (anonymous) | @ | grapes.min.js:2
Ā | s | @ | grapes.min.js:2
Ā | load (async) | Ā | Ā
Ā | o.renderScripts | @ | FrameView.ts:317
Ā | o.render | @ | FrameView.ts:292
Ā | n.render | @ | FrameWrapView.ts:195
Ā | e.add | @ | ModuleDomainViews.ts:60
Ā | (anonymous) | @ | ModuleDomainViews.ts:71
Ā | Ke | @ | each.js:14
Ā | (anonymous) | @ | backbone.js:1476
Ā | e.render | @ | ModuleDomainViews.ts:71
Ā | o._renderFrames | @ | CanvasView.ts:612
Ā | o._onFramesUpdate | @ | CanvasView.ts:103
Ā | g | @ | backbone.js:337
Ā | h | @ | backbone.js:322
Ā | c | @ | backbone.js:110
Ā | a.trigger | @ | backbone.js:312
Ā | set | @ | backbone.js:529
Ā | e._pageUpdated | @ | Canvas.ts:55
Ā | g | @ | backbone.js:336
Ā | h | @ | backbone.js:322
Ā | c | @ | backbone.js:110
Ā | a.trigger | @ | backbone.js:312
Ā | o._onPageChange | @ | index.ts:152
Ā | _e | @ | _executeBound.js:8
Ā | (anonymous) | @ | bind.js:10
Ā | (anonymous) | @ | restArguments.js:16
Ā | g | @ | backbone.js:337
Ā | h | @ | backbone.js:322
Ā | c | @ | backbone.js:110
Ā | a.trigger | @ | backbone.js:312
Ā | set | @ | backbone.js:529
Ā | o.select | @ | index.ts:258
Ā | (anonymous) | @ | index.ts:128
Ā | g | @ | backbone.js:336
Ā | h | @ | backbone.js:322
Ā | c | @ | backbone.js:110
Ā | a.trigger | @ | backbone.js:312
Ā | reset | @ | backbone.js:965
Ā | o.loadProjectData | @ | Module.ts:164
Ā | o.load | @ | index.ts:286
Ā | (anonymous) | @ | Editor.ts:856
Ā | o.loadData | @ | Editor.ts:856
Ā | (anonymous) | @ | Editor.ts:837
Ā | (anonymous) | @ | grapes.min.js:2
Ā | (anonymous) | @ | grapes.min.js:2
Ā | s | @ | grapes.min.js:2
Ā | Promise.then (async) | Ā | Ā
Ā | l | @ | grapes.min.js:2
Ā | (anonymous) | @ | grapes.min.js:2
Ā | vh | @ | grapes.min.js:2
Ā | o.load | @ | grapes.min.js:2
Ā | (anonymous) | @ | Editor.ts:335
Ā | (anonymous) | @ | grapes.min.js:2
Ā | (anonymous) | @ | grapes.min.js:2
Ā | (anonymous) | @ | grapes.min.js:2
Ā | vh | @ | grapes.min.js:2
Ā | (anonymous) | @ | Editor.ts:330
Ā | setTimeout (async) | Ā | Ā
Ā | o.loadOnStart | @ | Editor.ts:330
Ā | init | @ | index.ts:87
Ā | (anonymous) | @ | (index):616
trying to use a data URI instead of a file reference failed as well
Thanks for reporting this, @rozek.
The issue with canvas.script entries do not respect an "import map" appears to be a race condition or state management timing problem. This typically happens when component lifecycle events and DOM modifications overlap, creating an inconsistent state.
What to try:
- Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
// your operation here
}, 0);
-
Check initialization order ā make sure components are fully loaded before you interact with them
-
Use the editor's event system ā listen to completion events:
editor.on('component:mount', (component) => {
// safe to interact with component here
});
Recommended next steps:
- Test with the latest GrapesJS version if you haven't
- Provide a minimal reproducible example (CodeSandbox) ā this helps the team identify the root cause faster
- Include GrapesJS version, browser, and console errors in your report
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5353
canvas.script entries can not be JS modules
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.