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
[BUG] Unexpected token 'export'
with Jest (on Cloudflare Workers)
#678
Comments
I think this is due to a missing EDIT: I had a quick look and there are a lot of side effects in the project from adding |
The problem seems to be that Jest resolves the main file by using the As a workaround, I specified this in my Jest config: moduleNameMapper: {
'^uuid$': '<rootDir>/node_modules/uuid/wrapper.mjs'
} |
Hmm, even when doing this, I get:
I use:
|
Hm, it sounds pretty unusual that your setup would specifically pick the MJS file but then interpret it as CJS. But then in your case I guess the Personally I am using Jest in an ESM project, so I am using the ts-jest ESM setup. So I'm using the preset |
Ah, maybe it is because this is not an ESM project to begin with. I have another ESM project where I can run tests without issues, but I cannot migrate this project to ESM (yet). Edit: FWIW, I vendored the dependency, as I only needed parts of the package. |
Marking as stale due to 90 days with no activity. |
Go away stalebot. |
I tried this config, and It cause another problem ’RangeError: Maximum call stack size exceeded‘ |
@zhouyali this worked for me: |
Hello, we're seeing (I believe) this same problem. I tried to apply the
FWIW, we are not using/importing Any advice or suggestions would be greatly appreciated! Should we be adopting ts-jest (as mentioned by @cdauth) if we're testing a React/Typescript project? |
Before you begin...
Description of the problem
This issue is very similar to #451 - except I'm on v9 of this library, which is supposed to fix this issue. I'm also on Jest v29.3.1. I'm also also using Cloudflare workers - but I'm not sure how that influences this problem. The
moduleNameMapper
workaround still works.Stacktrace:
Recipe for reproducing
I made three small commits off the official cloudflare+jest example repo here which demonstrates the problem.
Environment
System:
OS: Windows 10 10.0.19045
CPU: (12) x64 Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
Memory: 12.58 GB / 63.73 GB
Binaries:
Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (108.0.1462.76)
Internet Explorer: 11.0.19041.1566
npmPackages:
@cloudflare/workers-types: ^3.11.0 => 3.11.0
@types/jest: 29.2.5 => 29.2.5
@types/uuid: ^9.0.0 => 9.0.0
esbuild: ^0.14.41 => 0.14.41
jest: 29.3.1 => 29.3.1
jest-environment-miniflare: ^2.5.0 => 2.5.0
miniflare: ^2.5.0 => 2.5.0
prettier: ^2.6.2 => 2.6.2
ts-jest: 29.0.4 => 29.0.4
typescript: ^4.7.2 => 4.7.2
uuid: ^9.0.0 => 9.0.0
wrangler: ^2.0.7 => 2.0.7
The text was updated successfully, but these errors were encountered: