2

I want to use detect-mobile package (https://github.com/hgoebl/mobile-detect.js/tree/v1.4.4) in Angular application.

But it can't be imported usual way. I've tried each of following:

import { MobileDetect } from 'mobile-detect';
import MobileDetect from 'mobile-detect';
import {}  from 'mobile-detect';

Mobile detect d.ts file has following structure:

enter image description here

What am I doing wrong and how should it be imported? Also I would be greatly appreciated for explanation how such package differs from others.

Stackblitz: https://stackblitz.com/edit/angular-3qptjt

1 Answer 1

1

The syntax used for the export - export = MobileDetect - means that the package was written use CommonJS style exports. See this ticket for further explanation.

Therefore the way to import this is:

import * as MobileDetect from 'mobile-detect'

Also, I believe if you are using the esModuleInterop TypeScript compiler flag, you can just write:

import MobileDetect from 'mobile-detect'
Sign up to request clarification or add additional context in comments.

2 Comments

but what the difference with jasmine-theories for example? It contains : declare var jsminTheories: jasmineTheories.jasmineTheoriesStatic; export default jsminTheories; and can be imported like: import theoretically from 'jasmine-theories'; Appreciate if you add some explanation to your answer.
Now I see that export default jsminTheories is ES6 module. But could you please add the explanation to the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.