Definitelytyped: [@types/animejs] Import issue.

Created on 19 May 2020  路  5Comments  路  Source: DefinitelyTyped/DefinitelyTyped

I can't import the default export. Import all-from does not work in this case.

works on runtime, but types error. (default import)

import anime from 'animejs';

does not work on runtime, but no errors with types.

import * as anime from 'animejs';

@types/[email protected]
[email protected]

Most helpful comment

Thanks for fast response @peterblazejewicz, i'm going to work on finding out what part of my project is the problem and i'll report back.

Edit:
Ok, for me the error was appearing in .vue files and not in .ts files. I reinstalled the whole package.json, switched the vetur.validation.script option in .vscode/settings.json off and back on and now the error is gone. No idea what happened but it's definitely nothing connected to @types/animejs. Sorry for the mess and thanks for the assistance.

All 5 comments

import anime =  require('animejs');

should work, the import anime from 'animejs' shold work if esModuleInterop is enabled in tsconfig.json. The module definition looks ok for me.
Is that CommonJS or ES module?

Same problem, Could not find declaration file for module 'animejs'. despite having the same packages as @infacto.
Tried both possible ways of importing ES6 module:

import anime from 'animejs';
import anime from 'animejs/lib/anime.es.js';

and both throws the same error. esModuleInterop is enabled and all of the other @types packages work without any problems.

folks, I really cannot see the issue when using general import (both CommonJS/ES2015):

import anime from 'animejs';

I think the direct import of module (import anime from 'animejs/lib/anime) is not suppported by this definition.

If you have problem using this specific type definition with your TS configuration, please make sure you post relevant TS configuration here.
One could figure out what is TSC is doing by asking to retrace resolution paths, for example with that package I've done this:

npx tsc --pretty --listFiles --traceResolution

here you can see relevant information about TSC finding proper types when using my local TS config (worked both for CommonJS and ES2015 targets), your local output could differ depending on settings.
Only part related to types for 'animejs' matched and resolved is posted below:

======== Resolving module 'animejs' from 'C:/development/tests/test-anime/index.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
Loading module 'animejs' from 'node_modules' folder, target file type 'TypeScript'.
Found 'package.json' at 'C:/development/tests/test-anime/node_modules/animejs/package.json'.
'package.json' does not have a 'typesVersions' field.
File 'C:/development/tests/test-anime/node_modules/animejs.ts' does not exist.
File 'C:/development/tests/test-anime/node_modules/animejs.tsx' does not exist.
File 'C:/development/tests/test-anime/node_modules/animejs.d.ts' does not exist.
'package.json' does not have a 'typings' field.
'package.json' does not have a 'types' field.
'package.json' has 'main' field 'lib/anime.js' that references 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js'.
File 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js' exist - use it as a name resolution result.
File 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js' has an unsupported extension, so skipping it.
Loading module as file / folder, candidate module location 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js', target file type 'TypeScript'.
File 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js.ts' does not exist.
File 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js.tsx' does not exist.
File 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js.d.ts' does not exist.
File name 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js' has a '.js' extension - stripping it.
File 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.ts' does not exist.
File 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.tsx' does not exist.
File 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.d.ts' does not exist.
Directory 'C:/development/tests/test-anime/node_modules/animejs/lib/anime.js' does not exist, skipping all lookups in it.
File 'C:/development/tests/test-anime/node_modules/animejs/index.ts' does not exist.
File 'C:/development/tests/test-anime/node_modules/animejs/index.tsx' does not exist.
File 'C:/development/tests/test-anime/node_modules/animejs/index.d.ts' does not exist.
Found 'package.json' at 'C:/development/tests/test-anime/node_modules/@types/animejs/package.json'.
'package.json' does not have a 'typesVersions' field.
File 'C:/development/tests/test-anime/node_modules/@types/animejs.d.ts' does not exist.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts'.
File 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts' exist - use it as a name resolution result.
Resolving real path for 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts', result 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts'.
======== Module name 'animejs' was successfully resolved to 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts' with Package ID '@types/animejs/[email protected]'. ========
======== Resolving type reference directive 'animejs', containing file 'C:/development/tests/test-anime/__inferred type names__.ts', root directory 'C:/development/tests/test-anime/node_modules/@types'. ========
Resolving with primary search path 'C:/development/tests/test-anime/node_modules/@types'.
Found 'package.json' at 'C:/development/tests/test-anime/node_modules/@types/animejs/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts'.
File 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts' exist - use it as a name resolution result.
Resolving real path for 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts', result 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts'.
======== Type reference directive 'animejs' was successfully resolved to 'C:/development/tests/test-anime/node_modules/@types/animejs/index.d.ts' with Package ID '@types/animejs/[email protected]', primary: true. ========

/cc @A-Babin @supaiku0 @southrock

Thanks for fast response @peterblazejewicz, i'm going to work on finding out what part of my project is the problem and i'll report back.

Edit:
Ok, for me the error was appearing in .vue files and not in .ts files. I reinstalled the whole package.json, switched the vetur.validation.script option in .vscode/settings.json off and back on and now the error is gone. No idea what happened but it's definitely nothing connected to @types/animejs. Sorry for the mess and thanks for the assistance.

@Oloro thx for update!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JudeAlquiza picture JudeAlquiza  路  3Comments

csharpner picture csharpner  路  3Comments

ArtemZag picture ArtemZag  路  3Comments

lilling picture lilling  路  3Comments

variousauthors picture variousauthors  路  3Comments