Closed EvHaus closed 2 years ago
Well, it didn't take long at all to get the answer to "do we still need the jsLoader
setting, and why?". One of the ways in which dynamic import isn't quite a drop-in replacement for require is that it only accepts paths that use a small predefined list of extensions, which doesn't include .jsx
.
I'm not sure how best to reconcile the conflict between providing good support for ES modules and supporting nonstandard (but very common) file extensions. But as a quick fix you can get around the problem by adding jsLoader": "require"
to your jasmine.json
file.
@sgravrock Darn, that sucks. I can confirm that jsLoader: "require"
fixes the problem.
Thanks for updating the docs in 1e133d6bebd6c51b9ebb4b91807db85a2fb4fdd4. Can I suggest updating the React documentation page here as well? Given that most React users will be following that guide I think the .jsx
info will be relevant to them there.
Done.
But I also think Jasmine can probably handle this transparently, by falling back to require()
when it gets that particular error code. The drawback I see is that it'd lead to more confusing errors if someone tries to use ES module syntax in a JSX file without transpiling, but hopefully that's a rare scenario.
Thanks! Going to close this issue as this addresses my initial issue.
Thanks to you both for handling this issue promptly. It resolved the same issue for .coffee
files in coffeelib.
I've also just released 4.0.1, which handles this situation without the need for a configuration change.
Confirmed. With 4.0.1 jsx
files work without jsLoader: "require"
. Thanks!
Are you creating an issue in the correct repository?
I hope so. Only the core
jasmine
dependency is used to reproduce this.Expected Behavior
Spec files with the
.jsx
extension should be loadable byjasmine@4
when used withbabel
.Current Behavior
Trying to load a
.jsx
file throws:Possible Solution
Not sure. This wasn't a problem in
jasmine@3.99
, so maybe the new ESM changes injasmine@4
are causing it?Suite that reproduces the behavior (for bugs)
https://stackblitz.com/edit/node-pmddnq?file=README.md
Context
Makes v4 somewhat un-useable for React projects.
Your Environment