added the import to my main.js file like this: import ‘animejs/anime.min’ (the path is correct, even the editor is pointing to the right file, and I also tried with the not minified version).
run: yarn run build
and I keep getting 6:25 error ‘anime’ is not defined no-undef
I have checked the forum and some people are using imports like this import {animejs} from ‘animejs/anime.min’;
which gives me this ’animejs’ is defined but never used no-unused-vars
which makes sense but even by trying to assign it to a variable it doesn’t work.
It’s worth noting that other libraries like “slick” are working without any problem. I have also checked the animejs package.json but there’s nothing odd there compared to, for example, slickcarousel package.json. The only difference that I could notice is this:
“files”: [
“anime.js”,
“anime.min.js”
],
Now in sage8 I was using overrides but that was with bower so it shouldn’t matter.
Sorry I tried to search but I couldn’t find any related issue with this library.
Thanks in advance.
Just did a test with a cloned sage theme and animejs,
import {animejs} from 'animejs';
build works fine for me.
Edit: I just noticed that you get this eslint error when you just import something but don’t use it, e.g. for testing as in this case. You have to actually use animejs for something in the code so eslint is happy.
Ok thanks for clarifying this. I might miss something though.
I added the import as you did on my “main.js”, added “animejs”: true to the “globals” in .eslintrc and I am using just a simple test in my common.js (inside the “routes” folder) like this
let title = document.getElementsByClassName('entry-title');
anime({
targets: title,
translateX: 250
});
You’ll want to be importing anime not animejs, since animejs is just the package name and there are no exports referred to as animejs anywhere in the code.
Thanks it works. I followed the suggestion above from @strarsis but apparently the import was wrong. He used import {animejs} from ‘animejs’; and he said it was working so I always used that one…
So yeah the solution is running the import directly where you need it (either common.js, home.js etc…) and have it like this import anime from ‘animejs’;
Thanks for the solution @MWDelaney and I apologise if I wasn’t clear enough.