[英]Can't get Animejs library to work in my typescript & webpack project
I recently switched from ES5 to typescript and webpack. My wish is to use the Threejs library (no problems there, yet.) and the Animejs library for its fancy timeline animation functions: Spent all day yesterday trying to get it to work (you know the drill. 30+ tabs open), I followed the instructions in the Animejs documentation,我最近从 ES5 切换到 typescript 和 webpack。我的愿望是使用 Threejs 库(目前还没有问题。)和 Animejs 库用于其花哨的时间轴 animation 功能:昨天花了一整天试图让它工作(你知道钻。打开 30 多个选项卡),我按照 Animejs 文档中的说明进行操作,
npm install animejs --save
npm 安装 animejs --save
then然后
import anime from 'animejs/lib/anime.es.js';
... and I got the error: ...我得到了错误:
Could not find a declaration file for module 'animejs/lib/anime.es.js'
找不到模块“animejs/lib/anime.es.js”的声明文件
I made sure they were installed with the command:我确保它们是使用以下命令安装的:
npm i --save-dev @types/animejs
npm i --save-dev @types/animejs
I checked the @types folder and there ís an Animejs folder with an index.d.ts file inthere.我检查了@types 文件夹,那里有一个带有 index.d.ts 文件的 Animejs 文件夹。 I also checked the tsconfig and it checks this folder for declaration files.
我还检查了 tsconfig 并检查此文件夹中的声明文件。
{
"compilerOptions": {
"moduleResolution": "node",
"strict": true
},
"typeRoots": [
"./node_modules/@types/"
],
"noImplicitAny": false,
"include": ["**/*.ts", "test"]
}
After some googlin' I found that if I just changed the implementation method the error is resolved.经过一番谷歌搜索后,我发现如果我只是更改实现方法,错误就会得到解决。 Animejs' doc says it should be as follows:
Animejs 的文档说它应该如下所示:
import anime from 'animejs/lib/anime.es.js';
I changed that to this: (and the error was gone)我将其更改为:(错误消失了)
import * as anime from 'animejs';
Now as I'm clearly a novice in this new pipeline, I hardly see how that made a difference.现在我显然是这个新管道的新手,我几乎看不出这有什么不同。 But I have a new problem now: when I declare a new anime animation (example code below is from Animejs' documentation)..
但是我现在有一个新问题:当我声明一个新的动漫 animation 时(下面的示例代码来自 Animejs 的文档)..
anime({
targets: '.css-selector-demo .el',
translateX: 250
});
..it does compile, but I get an error in the JS console (using Chrome) ..它确实可以编译,但我在 JS 控制台中收到错误消息(使用 Chrome)
Uncaught TypeError: anime is not a function
未捕获的类型错误:动漫不是 function
Now I'm lost .现在我迷路了。 Don't have any colleagues to ask either.
也没有同事可以问。 Please help!
请帮忙!
Try this尝试这个
import anime from 'animejs';
This is what I personally use on a regular basis.这是我个人经常使用的。 I also don't use
@types/animejs
so I think you can safely uninstall the package.我也不使用
@types/animejs
,所以我认为您可以安全地卸载 package。
Right.正确的。 Thanks for the help so far, I did figure it out eventually.
感谢到目前为止的帮助,我最终确实弄明白了。 kind of.
的种类。 So what I did was I used this line to import it
所以我所做的就是使用这一行来导入它
import anime from 'animejs/lib/anime.es.js';
Then I uninstalled and reinstalled the animejs framework, including it's @types.然后我卸载并重新安装了 animejs 框架,包括它的@types。 This is what my tsconfig.json now looks like (I also made some changes here, with a little help from a friend).
这就是我的 tsconfig.json 现在的样子(在朋友的帮助下,我在这里也做了一些更改)。
{
"compilerOptions": {
"moduleResolution": "node",
"strict": true,
"allowJs": true,
},
"typeRoots": [
"../node_modules/@types/"
],
"noImplicitAny": false,
"include": ["**/*.ts", "test"]
}
I'm not entirely certain which change did the trick, but the trick it did.我不完全确定是哪个更改起作用了,但确实起作用了。 Hopefully anyone struggling with this same issue may find this useful!
希望任何为同样的问题而苦苦挣扎的人都会觉得这很有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.