-
-
Notifications
You must be signed in to change notification settings - Fork 914
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? |
Any chance #736 helps with this? (asking only because CFWorkers are mentioned there. I don't have time to investigate this in depth at the moment, as I'm focused on rolling a new release for RFC9562) |
@AlexErrant et al: I've just published uuid@11 (prerelease) as The caveat here is that I didn't deliberately set out to fix this as part of v11. It's more that v11 was a substantial rewrite that included switching the source to TypeScript, and switching the transpiler from Basically I'm not too surprised this issue has gone away, but nor can I tell you why it went away. tl;dr: I'm going to close this out because it solve's Alex's issue, but I can't say if it'll solve the issue for the rest of you. Please do test out the new version and let me know if you see issues. Verifying issue exists using Alex's example repo: $ git clone https://github.com/AlexErrant/miniflare-typescript-esbuild-jest.git
$ cd miniflare-typescript-esbuild-jest
$ npm install # this installs uuid@9
$ npm test
# <snip>
# ....
/private/tmp/foo/miniflare-typescript-esbuild-jest/node_modules/uuid/dist/esm-browser/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js'; Testing with $ npm install uuid@10
$ npm test
# <snip... same error as above> Verifying issue is fixed in v11 (prerelease): $ npm install uuid@beta
$ npm test
# <snip>
PASS test/index.spec.ts
PASS test/response.spec.ts
PASS test/counter.spec.ts |
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: