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
Import with Typescript and Babel VS import with just Typescript #3650
Comments
I would recommend against using |
As I tried to describe in the issue, doing that results in |
Did you manage to solve this problem? |
No. I changed my testing approach to work around it. Still curious about a solution. |
I see. I'm having a similar problem trying to AoT-compile Angular2 (which requires me to use |
Anyone figured out a solution to this? Moment doesn't seem to be usable with TypeScript at all due to this... |
A way to get this to work is to output |
@hojberg Can you please elaborate your suggested fix (or tell what needs to be changed where for the noobs) |
@opavader I've been struggling with this for weeks now. It finally just dawned on me. In your
So my complete file looks like this:
YMMV but this seems to work with my configuration with Webpack, Typescript, and all the other stuff my template created for me. Edit; This broke some functionality such as isometric-fetch in my site. |
I am already using |
Any news on this? |
@darkbasic I was running into this issue as well, but just discovered a fix for my own situation. I deleted the entire node_modules directory and the package-lock.json file, then reinstalled all of the modules, rebuilt the project and the error went away. The Sr. dev on my team thinks that one of the packages was slightly out of sync and causing the issue, this may not be the case for everyone but it might help. |
That happens with the parcel.js bundle. See: parcel-bundler/parcel#1194 moment/moment#3650 palantir/blueprint#959
@subvertallchris @rawrmaan @vittau hello guys, is there any one fixed this issue? i just run into this issue, you can reproduce it with project here. Of cause, you can fix it by modify es6 module to commonjs module in tsconfig.json or just rewrite |
by the way, issue has been posted in webpack and Stack Overflow |
Guys, here's what worked for me. (Working with TS 2.7+). |
Is this still an issue with TS and Babel? |
I'm using Moment 2.17.1 with TypeScript 2.1.1, OS X (10.11.6) and Node 6.3.0. I'm having trouble importing moment consistently.
In our dev and prod environments, we use Babel to compile. In that scenario, this import statement works:
This works in the browser but causes
TypeError: moment_1.default is not a function
in my mocha tests.Our test code is built without babel, just
tsc
to an output directory and we run from there. In that case, we have to use this statement:This makes node happy but brings back the dreaded
moment is not a function(…)
error when that code is hit in the browser.Naturally, I need to find one import to rule them all if I want to test any code that uses moment.
I have enabled
allowSyntheticDefaultImports
in both environments' tsconfigs. My guess is that the presence of Babel is complicating things but I don't know what the solution is. Would love some advice. Thank you!The text was updated successfully, but these errors were encountered: