# \`LoadError: cannot load such file\` on plugin external gem

**URL:** https://meta.discourse.org/t/loaderror-cannot-load-such-file-on-plugin-external-gem/239625
**Category:** Development
**Created:** [September 21, 2022, 7:30am UTC](https://meta.discourse.org/t/loaderror-cannot-load-such-file-on-plugin-external-gem/239625 "2022-09-21T07:30:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mjsir911](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mjsir911/32/264466_2.png) [@mjsir911](https://meta.discourse.org/u/mjsir911)
#### Post date: [September 21, 2022, 7:30am UTC](https://meta.discourse.org/t/loaderror-cannot-load-such-file-on-plugin-external-gem/239625/1 "2022-09-21T07:30:28Z")

</div>

Hi.

I’m trying to develop [this](https://github.com/mjsir911/discourse-telegram-auth) plugin and am having issues with external dependencies.

My dependency is specified in `plugin.rb` with `gem 'omniauth-telegram', '0.2.1'` which is the  
recommended way to require dependencies I believe? I’m bringing it into the docker container with this:

```plaintext
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/mjsir911/discourse-telegram-auth.git

```

Results in this error:

```plaintext
I, [2022-09-21T07:17:21.579540 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'LOAD_PLUGINS=0 bundle exec rake plugin:pull_compatible_all'
I, [2022-09-21T07:17:22.713904 #1] INFO -- : discourse-telegram-auth is already at latest compatible version
docker_manager is already at latest compatible version

I, [2022-09-21T07:17:22.714304 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
rake aborted!
LoadError: cannot load such file -- omniauth-telegram
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/var/www/discourse/lib/plugin_gem.rb:30:in `load'
/var/www/discourse/lib/plugin/instance.rb:776:in `gem'
/var/www/discourse/plugins/discourse-telegram-auth/plugin.rb:9:in `activate!'
/var/www/discourse/lib/plugin/instance.rb:670:in `instance_eval'
/var/www/discourse/lib/plugin/instance.rb:670:in `activate!'
/var/www/discourse/lib/discourse.rb:314:in `block in activate_plugins!'
/var/www/discourse/lib/discourse.rb:311:in `each'
/var/www/discourse/lib/discourse.rb:311:in `activate_plugins!'
/var/www/discourse/config/application.rb:228:in `block in <class:Application>'
/var/www/discourse/lib/plugin.rb:6:in `initialization_guard'
/var/www/discourse/config/application.rb:227:in `<class:Application>'
/var/www/discourse/config/application.rb:81:in `<module:Discourse>'
/var/www/discourse/config/application.rb:80:in `<top (required)>'
/var/www/discourse/Rakefile:7:in `require'
/var/www/discourse/Rakefile:7:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
(See full trace by running task with --trace)
I, [2022-09-21T07:17:23.851899 #1] INFO -- : gem install omniauth-telegram -v 0.2.1 -i /var/www/discourse/plugins/discourse-telegram-auth/gems/2.7.6 --no-document --ignore-dependencies --no-user-install
Successfully installed omniauth-telegram-0.2.1
1 gem installed

I, [2022-09-21T07:17:23.852119 #1] INFO -- : Terminating async processes
I, [2022-09-21T07:17:23.852174 #1] INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main pid: 57
I, [2022-09-21T07:17:23.852234 #1] INFO -- : Sending TERM to exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 118
118:signal-handler (1663744643) Received SIGTERM scheduling shutdown...
2022-09-21 07:17:23.852 UTC [57] LOG: received fast shutdown request
2022-09-21 07:17:23.855 UTC [57] LOG: aborting any active transactions
2022-09-21 07:17:23.860 UTC [57] LOG: background worker "logical replication launcher" (PID 66) exited with exit code 1
2022-09-21 07:17:23.860 UTC [61] LOG: shutting down
2022-09-21 07:17:23.878 UTC [57] LOG: database system is shut down
118:M 21 Sep 2022 07:17:23.936 # User requested shutdown...
118:M 21 Sep 2022 07:17:23.936 * Saving the final RDB snapshot before exiting.
118:M 21 Sep 2022 07:17:23.937 * DB saved on disk
118:M 21 Sep 2022 07:17:23.937 # Redis is now ready to exit, bye bye...

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 1212 exit 1>
Location of failure: /usr/local/lib/ruby/gems/2.7.0/gems/pups-1.1.1/lib/pups/exec_command.rb:117:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
bootstrap failed with exit code 1
**FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.

```

Related posts where the fixes don’t apply to me:

> [@Having a hard time installing \`eth\` gem in a plugin in production](https://meta.discourse.org/t/having-a-hard-time-installing-eth-gem-in-a-plugin-in-production/217496):
>
> I’m having to install the eth gem in a plugin but really having a hard time doing that. It depends on a bunch of other gems, a few of which have native extensions. Here’s the dependency list if you wanna give it a try. gem 'pkg-config', '1.4.7', require: false gem 'mkmfmf', '0.4', require: false gem 'keccak', '1.3.0', require: false gem 'zip', '2.0.2', require: false gem 'mini\_portile2', '2.7.0', require: false gem 'rbsecp256k1', '5.1.0', require: false gem 'konstructor', '1.0.2', require: fals…

> [@Plugin with custom gems](https://meta.discourse.org/t/plugin-with-custom-gems/57190):
>
> I’ve some custom gems in my plugin. it works fine on local machine. but on prod while following your app.yml format for installing private plugins, it fails with following error. I, [2017-02-09T17:13:20.015101 #13] INFO – : \> cd /var/www/discourse && sudo -E -u discourse bundle exec rake assets:precompile ERROR: While executing gem … (Errno::EACCES) Permission denied @ dir\_s\_mkdir - /var/www/discourse/plugins/my-plugin/gems I, [2017-02-09T17:13:26.998142 #13] INFO – : Your home director…

> [@Plugin using own gem](https://meta.discourse.org/t/plugin-using-own-gem/50007):
>
> I am developing a plugin that needs to use an external gem, namely docx in order to generate word docs. Is there someway to do this or do I have to append it to the Gemfile?

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [September 29, 2022, 5:57am UTC](https://meta.discourse.org/t/loaderror-cannot-load-such-file-on-plugin-external-gem/239625/3 "2022-09-29T05:57:40Z")

</div>

I’ve attempted a few things and made a PR to your plugin and the fix seems to be working.

[https://github.com/mjsir911/discourse-telegram-auth/pull/1](https://github.com/mjsir911/discourse-telegram-auth/pull/1)
