Cannot import discourse libs in markdown extensions

סיכום מבוסס בינה מלאכותית

jack2 is experiencing issues importing Discourse libraries in their Markdown extension. The error occurs when trying to import libraries outside of the pretty-text folder, specifically when the Markdown engine is executed server-side to generate the cooked version of a post. jack2 suspects this might be due to the fact that they cannot rely on client-side libraries.

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

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.