-
Notifications
You must be signed in to change notification settings - Fork 145
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
Jasmine loads test dependency as CommonJS module instead of ESM #191
Comments
Thanks for the minimal reproduction. That was very helpful. I think this is a problem with fetch-mock. The first things that jumped out at me are that it's your code rather than Jasmine that imports fetch-mock, and that your code looks fine. I was able to reproduce the problem with a simple test file I added to your repo, without using Jasmine at all:
I was also able to reproduce the error in a pure CommonJS project. I think there are two things going on here:
It looks like you'll have to downgrade node-fetch to a compatible version if you want to use fetch-mock. |
Good catch on the unsupported version, I totally missed that. Downgrading |
I have a project which uses ES modules and tests using Jasmine. In my tests, I am using
fetch-mock
to mock web requests. When running the tests, I get the following error:It seems that instead of loading
fetch-mock
as an ES module, it is loaded as a CommonJS module (it contains both). For running the binary, I could understand that (since Jasmine does not set"type": "module"
inpackage.json
). However I would expect it to work when running from my own script. And of course best case also running the binary should work directly.Versions:
To help with analysis, I created a small project which reproduces the issue: https://github.com/mdreier-work/jasmine-esm-bug
You can clone and
npm install
, then reproduce the issue with either of the following commands:npm test
(running/spec/support/jasmine.js
npx jasmine
(running the Jasmine binary)The text was updated successfully, but these errors were encountered: