-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Imports broken in babel-jest when using babel and @babel/typescript #5542
Comments
This looks like a bug with how Babel handles import statements, which is different from how typescript compiler does it as linked in the issue.
Webpack has native support for imports, and looks like the way it handles imports is different from the way Babel handles them. Jest relies on Babel to transpile imports and doesn't support it natively, so it won't be possible for Jest to do it without a custom transformer which transpiles those import statements AFAIK. |
I believe I'm running into a similar issue, except without TypeScript. Here's a repo demonstrating the issue, it's simplified from the |
@AndrewSouthpaw I cannot repro (tried several times to test cache run). This is probably something with your package manager. Try removing |
I had the same problem, but removing the |
Otherwise it's fine. I've tried doing a fresh install of |
Wow. That was a shockingly simple fix, and strange that Either way, thank you so much! This had a couple of us on the flow-typed team stumped! |
😅glad you have this sorted now! |
It appears that
to my Also, I had to |
We currently point people to |
Found this issue trying to add support for
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
It appears that Jest doesn't play nice with TypeScript that's compiled exclusively via Babel -- e.g. without
tsc
.If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can
yarn install
andyarn test
.I've got a minimal repro here: https://github.com/japhar81/JestRepro
#3202 indicates that the issue is with
{"modules":false}
. Indeed,yarn test
with that setting yields an error;SyntaxError: Unexpected token import
. Removing that setting (as in the repro code), yields a different errorTypeError: (0 , express) is not a function
.Digging further lead me to this issue: microsoft/TypeScript#5458 -- and I can confirm that if I change my import to be
import express from 'express'
, things work, though of course TypeScript is angry as there's no real default export in the express definition.#3202 (comment) references using
Adding those in this same repo has no effect. The error remains
TypeError: express is not a function
. It's possible these are no longer valid for Babel 7 and different plugins should be used -- I've had no luck identifying if that's the case.What is the expected behavior?
There should be some way to keep TypeScript happy with
import * as express from 'express'
and still have Jest operate. Asyarn start
demonstrates in this sample, it does compile and work with{"modules":false}
in webpack. I'm not entirely sure where the difference is, but presumably if Webpack can do it, Jest can as well.Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
Mac OS X 10.13.3
Yarn: 1.3.2
npm: 5.6.0
node: 9.3.0
Jest: 22.2.2
See Repo for Config
The text was updated successfully, but these errors were encountered: