Cannot import discourse libs in markdown extensions

Continuing the discussion from Developer's guide to Markdown extensions:


My extension code is like this:

import { iconHTML } from 'discourse-common/lib/icon-library'

export function setup(helper) {
   ...
}

When doing a bundle exec rake db:create db:migrate, I get this error:

== Seed from /home/jack/discourse/db/fixtures/500_categories.rb
rake aborted!
MiniRacer::RuntimeError: Error: Could not find module `discourse-common/lib/icon-library` imported from `lib/discourse-markdown/my_bbcode_plugin`

When running the plugin, everything works fine in the composer: I can use my new bbcode as expected. But when saving the post, I get this error:

MiniRacer::RuntimeError at /posts/30
====================================

> Error: Could not find module `discourse-common/lib/icon-library` imported from `discourse-markdown/discpage`

In fact, as far as I can tell, the problem occurs when trying to import any Discourse file, except for those in the pretty-text folder.

Is this the expected behavior ?

Iā€™m on Window WSL and I noticed this somewhat similar issue from @vinothkannans

2 Likes

I think I get it: the markdown engine is also executed server-side (to generate the cooked version of the post). Hence the fact that I cannot rely on client-side libraries.

3 Likes