I'm new to Rails 6 + Webpack, so bear with me.
I'm trying to load aos.js
into Rails 6, and then call it from a view file.
I've created javascript/custom/aos.js
which contains this code with the following snippet appended:
console.log("typeof(AOS): " + typeof(AOS))
My application.js
is here:
require("jquery")
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("custom/aos") // <===== The custom file I'm importing
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);
require("trix")
require("@rails/actiontext")
When I load my page, I get:
typeof(AOS): undefined
so I know the file is being included, but AOS remains undefined.
However, when I include a javascript_include_tag
with the CDN link, or simply paste the CDN code into the console, AOS is defined and everything works fine.
Why is AOS undefined when I require it in application.js? Thanks for your help!
const AOS = require('custom/aos')
in the pack file instead.