Reputation: 2687
I tried use the type-definition for hammerjs. As:
import Hammer from 'hammerjs';
But i get this error:
Error TS2307: Cannot find module 'hammerjs'
I have two question. First, is necessary get all files of tile definition in github, our i can get the simples definition for hammerjs?
My package.json contains:
"dependencies": {
"git+https://[email protected]/DefinitelyTyped/DefinitelyTyped.git"
}
The second question, whats my error about import module?
Upvotes: 3
Views: 10699
Reputation: 180
Hammerjs may not be the same as chrome extention typings I was dealing with but issue sounds very much like what I was experiencing when you are missing an import or export in the module file you will need to give a reference:
Step 1: npm install --save @types/chrome
Step 2: Add /// to code needing to use modules
Step 3: that file can access all the declared modules.[do not import chrome or '@types/chrome'] https://typescript.codeplex.com/wikipage?title=Modules%20in%20TypeScript
Upvotes: 0
Reputation: 2687
I resolve the problem after read: http://x-team.com/2016/06/include-javascript-libraries-in-an-ionic-2-typescript-project/
I installed hammerjs with the command:
typings install github:DefinitelyTyped/DefinitelyTyped/hammerjs/hammerjs.d.ts#de8e80dfe5360fef44d00c41257d5ef37add000a --global --save
Then still appeared the error:
Error TS2307: Cannot find module 'hammerjs'
I am development the app with ionic2, i found that the compiler of typescript look the file main.d.ts and not index.d.ts. After rename the file index.d.ts to main.d.ts and works fine! The file main.d.ts found in root-your-app/typings
For import in the project i use: import * as Hammer from 'hammerjs';
Upvotes: 5
Reputation: 1801
Obviously you misuse the package.json dependencies.
Please read at https://github.com/DefinitelyTyped/DefinitelyTyped#how-to-get-the-definitions how to use the definition provided there, or at https://www.npmjs.com/package/typings how to use the newer 'typings' definitions.
To answer your first question, you will only need the definition for your project dependencies.
To answer your second question, the typescript compiler attempt to load the hammerjs dependency but cannot find it. You have to add it as a dependency in your package.json and install it using npm.
Upvotes: 1