# How to ship javascript library with plugin?

**URL:** https://meta.discourse.org/t/how-to-ship-javascript-library-with-plugin/53190
**Category:** Development
**Created:** [November 21, 2016, 12:07pm UTC](https://meta.discourse.org/t/how-to-ship-javascript-library-with-plugin/53190 "2016-11-21T12:07:04Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### Author: ![DawnPaladin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dawnpaladin/32/207237_2.png) [@DawnPaladin](https://meta.discourse.org/u/DawnPaladin)
#### Post date: [April 21, 2021, 10:57pm UTC](https://meta.discourse.org/t/how-to-ship-javascript-library-with-plugin/53190/10 "2021-04-21T22:57:41Z")

</div>

Thank you, that’s very helpful! Putting my library in the assets/lib folder is helping a lot.

Now that I have the correct path to it, the library is misbehaving. 🤦‍♂️ It’s a large library with lots of submodules - argdown.js requires ArgdownApplication.js and a bunch of others. When it tries to load ArgdownApplication.js it says “Uncaught ReferenceError: exports is not defined.”

I’ve tried bundling the whole thing into one file using Webpack, but for some reason the bundle is missing a third-party library called “punycode”. I’ve tried adding punycode into the compiled module, I’ve tried uploading it to the lib folder and adding `register_asset 'lib/punycode.js'` to plugin.rb, and I’m not having much luck.

The library works on my computer and in another plugin I’ve written. Is there a recommended way to add an NPM module to a Discourse plugin? [This thread](https://meta.discourse.org/t/how-to-install-npm-packages-in-custom-themes-plugins/142695/2) says to copy the module’s folder into your /lib/ folder; that’s not working for me.\* Can you point me to an example of someone successfully shipping a complex NPM module with a Discourse plugin so I can see what I’m doing wrong?

\*In that thread they’re trying to load the module remotely from [unpkg.com](http://unpkg.com); I’d rather do it locally, although maybe I should try that.

---

_[View the full topic](https://meta.discourse.org/t/how-to-ship-javascript-library-with-plugin/53190)._
