How can I require a Yarn package in the Rails assets?

1.1k views Asked by At

I have installed the package progressbar.js using $ yarn add progressbar.js. Now I am trying to require it by adding //= require progressbar.js to my application.js, but that gives me an error every time I try to load a page:

ActionView::Template::Error (couldn't find file 'progressbar.js' with type 'application/javascript'...

I have successfully used the same process to install and require jquery. Trying another package with a dot in its name like ipaddr.js fails with the same error, so I suspect that there's something special going on with packages with a dot in their name.

1

There are 1 answers

4
Roman Kiselenko On BEST ANSWER

I think you should require exact the js file of this lib:

//= require progressbar.js/src/main.js

or

//= require ipaddr.js/lib/ipaddr.js