Save 36% for Black Friday! Learn more

All threads / Adding external .js files to a new Rails 6 web app

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Adding external .js files to a new Rails 6 web app

Safwan SM asked in Rails

I have created a new rails 6 app. in rails 6, javascript folder is outside assets. I have copied all the css and js files from an existing application to this new one and application.css,application.js are updated. application.css working fine but application.js is not working. while compiling(bin/webpack) webpack it is showing error like this => ERROR in ./app/javascript/packs/application.js
Module not found: Error: Can't resolve 'file_name' in '/home/app/javascript/packs'
@ ./app/javascript/packs/application.js
in application.js i have added those .js files with require('file_name') syntax. and i pasted all the .js files on 'app/javascript/packs' folder. please help me to solve this issue.

I have created src folder inside app/javascript folder and pasted all .js files into it. application.js also done by require('src/file_name'), and then I changed webpacker.yml resolved_paths to resolved_paths: ['app/javascript/src'] . Now it is working fine.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 39,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.