You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have read Caveats documentation and didn't find a solution for this problem there.
Bug description
My jest tests were fine with aws-sdk-client-mock-jest@4.0.2 but as soon as I upgrade to 4.1.0 I am getting
Details:
/Users/s0046755/projects/adam-assumptions-model-inputs/node_modules/aws-sdk-client-mock-jest/dist/es/jest.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { __assign, __spreadArray } from "tslib";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
I am running in Node.js 20.17.0 and for jest I run it with NODE_OPTIONS=--experimental-vm-modules jest so I can use es modules.
Problem is resolved if package.json exports is removed
I was able to diff the aws-sdk-client-mock-jest package.json of 4.0.2 and 4.1.0 and found that the newer package.json includes an exports property. It appears that the inclusion of this is not playing well with jest causing the above error. If I manually remove the exports property from your package.json in node_modules/aws-sdk-client-mock-json then things once again work fine. So there must be some incompatibility with jest and the exports property.
Apparently the exports property was added to support the vitest feature.
jeffbski-rga
changed the title
aws-sdk-client-mock-jest 4.1.0 package.json exports causes SyntaxError: Cannot use import statement outside a module
aws-sdk-client-mock-jest 4.1.0 package.json exports causes "SyntaxError: Cannot use import statement outside a module" when using es modules
Oct 15, 2024
Seeing a "might-be-related" issue: seems core jest functions are being "stomped" on by these, when webpacked. Result is jest module mocks (non-SDK) aren't working, with "moduleName.mockImplementation..." resulting in a ts-loader error: "Property 'mockImplementation' does not exist on type 'xyz'.". Seems similar to Similar to #180?
The places where I do non-SDK jest mocking are referencing ./node_modules/aws-sdk-client-mock-jest/dist/types/jest.d.ts instead of ./node_modules/@types/jest/index.d.ts. Going back to 4.0.2 fixes it.
Checklist
Bug description
My jest tests were fine with aws-sdk-client-mock-jest@4.0.2 but as soon as I upgrade to 4.1.0 I am getting
Details:
I am running in Node.js 20.17.0 and for jest I run it with
NODE_OPTIONS=--experimental-vm-modules jest
so I can use es modules.Problem is resolved if package.json exports is removed
I was able to diff the aws-sdk-client-mock-jest package.json of 4.0.2 and 4.1.0 and found that the newer package.json includes an exports property. It appears that the inclusion of this is not playing well with jest causing the above error. If I manually remove the exports property from your package.json in node_modules/aws-sdk-client-mock-json then things once again work fine. So there must be some incompatibility with jest and the exports property.
Apparently the exports property was added to support the vitest feature.
Reproduction
Gist with all necessary code to reproduce the problem
https://gist.github.com/jeffbski-rga/97f15fbffb23aa7f91484da49aa7d21d
package.json
index.test.mjs
Reproduce in Node.js 20.17.0 by running
npm t
Simply attempting to import the module will cause the error.
Environment
Solution
Removing the exports property from the aws-sdk-client-mock-jest package.json fixes the problem.
The exports in 4.1.0 package.json (remove this to fix, but it may affect vitest feature since it was added for that)
4.0.2 did not have exports and it works properly.
The text was updated successfully, but these errors were encountered: