I have a very simple Node.js (12.16.3
) application that uses Express 4.17.1
. I'm trying to use Jest 26.0.1
to run the test suite, but the same is failing due to some issue with the uuid
module (version 8.1.0
) used across the entire project:
[x80486@uplink:~/Workshop/node-guacamole]$ npm run test
> [email protected] test /home/x80486/Workshop/node-guacamole
> node --experimental-modules --experimental-vm-modules ./node_modules/.bin/jest --coverage --detectOpenHandles --forceExit --verbose
(node:71155) ExperimentalWarning: The ESM module loader is experimental.
FAIL src/domain/customer.test.js
● Test suite failed to run
SyntaxError: The requested module 'uuid' does not provide an export named 'v4'
at jasmine2 (node_modules/jest-jasmine2/build/index.js:228:5)
FAIL src/service/customer.service.test.js
● Test suite failed to run
SyntaxError: The requested module 'uuid' does not provide an export named 'v4'
at async Promise.all (index 4)
at jasmine2 (node_modules/jest-jasmine2/build/index.js:228:5)
FAIL src/handler/customer.handler.test.js
● Test suite failed to run
SyntaxError: The requested module 'uuid' does not provide an export named 'v4'
at async Promise.all (index 2)
at async Promise.all (index 7)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 3 failed, 3 total
Tests: 0 total
Snapshots: 0 total
Time: 0.63 s
Ran all test suites.
I'm importing the module like: import { v4 } from "uuid"
; and on the other hand, the application runs successfully:
[x80486@uplink:~/Workshop/node-guacamole]$ npm run start:dev
> [email protected] start:dev /home/x80486/Workshop/node-guacamole
> nodemon --experimental-modules --experimental-vm-modules ./src/main.js
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node --experimental-modules --experimental-vm-modules ./src/main.js`
(node:74672) ExperimentalWarning: The ESM module loader is experimental.
2020-06-03T03:28:48.889Z [debug] - Server running at http://localhost:8080
2020-06-03T03:28:48.889Z [info] - Press CTRL-C to stop
...and everything works fine. I'm puzzled... I don't understand why this fails with Jest only. Is there something else I need to do to make it work?
import
the package when it failed initially, but then the application didn't work, so I went back because what I had initially (and have now) was the recommended way from theuuid
developers. Thanks for the explanation! – Anthropomorphosis