-
-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update instructions to use default import #284
Update instructions to use default import #284
Conversation
Similar to #236, Jest was failing for me using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, but I'm not sure about this asterisk for import :)
But, it works for ES6 for sure :) I don't know why exactly we need that asterisk for TypeScript. |
If it doesn't work for TypeScript, are you open to adding a third option for ES6? |
@lancedikson I tried to edit the import from/to: import * as Bowser from "bowser";
import Bowser from "bowser"; and webpack tells me tells me
Then I tried to do, as you said, to change from/to export = Bowser;
export default Bowser; And it compiles correctly, VSCode is able to find the typings but... SURPRISE, when I try to execute in the browser it tells me:
Those are the same errors I got while testing for #277. @lancedikson we need the asterisk because we decided to adopt the export of a namespace, which seems is the simplest way (and the unique one) to achieve this with typescript. As I explained in #277, since Bowser is a class with static methods (so Anyway, I don't know how Jest works, @JBallin. You are transpiling TS to JS and then execute the tests? |
Thanks, @alexandercerutti. I think we're pretty ok with having three lines of declaration for Bowser: CJS, ESM and TS. |
I've an update @lancedikson: I discovered that if we set in our esModuleInterop: true It will allow us to use it as Look at CompilerOptions for I also found that if we do this option, it does not change nothing between So I think we might just write in Readme: const Bowser = require("bowser"); // CommonJS
import * as Bowser from "bowser" // Typescript
import Bowser from "bowser" // ES6 and Typescript with --esModuleInterop enabled |
I should’ve clarified that I’m using create-react-app which has a built-in babel preset. Sorry for the confusion, I’m NOT using TypeScript. I think having three lines is the best solution (adding ES6). I’m not sure it’s necessary to mention esModuleInterop? Will adj PR once I get confirmation. |
Oh, okay. I'm using typescript + React with Webpack, so babel too. |
Incorporated feedback, let me know if there any other improvements that can be made. |
Reason: esModuleInterop is enabled in tsconfig. Refs: bowser-js/bowser#284
* fix(util-user-agent-browser): use default import from bowser * fix: use default import for bowser Reason: esModuleInterop is enabled in tsconfig. Refs: bowser-js/bowser#284
No description provided.