Issue #5354šŸ’¬ AnsweredOpened September 1, 2023by rozek0 reactions

Canvas.script entries do not respect an "import map"

Quick answerby artf

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)

rozek• September 4, 2023

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
rozek• September 4, 2023

trying to use a data URI instead of a file reference failed as well

ClaudeCode• May 17, 2026

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:

  1. Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
  // your operation here
}, 0);
  1. Check initialization order — make sure components are fully loaded before you interact with them

  2. 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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.