Create React App: Jest tests fails to find the module declaration
Describe the bug
Hi, I added this library to our project and couldn't get tests to run. I also found workaround for it. I attaced minimal reproduction, made with create react app. import-error.zip
All i did was that i imported and used useTimezoneSelect
Steps to reproduce: unzip import-error.zip cd import-error npm install npm test
Expected: Test runs fine
Actual result: Test fails
After adding this to package.json, it works fine
"jest": {
"moduleNameMapper": {
"react-timezone-select": "<rootDir>/node_modules/react-timezone-select/dist/index.js"
},
"transformIgnorePatterns": [
"node_modules/(?!simple-keyboard-layouts/build/layouts)/"
]
},
Seems to be something related to earlier bug https://github.com/ndom91/react-timezone-select/issues/54
This only happens on tests though. npm start and npm run build works fine .
Reproduction
Steps to reproduction
System Info
System info:
System:
OS: Linux 5.10 Ubuntu 20.04.6 LTS (Focal Fossa)
CPU: (16) x64 Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
Memory: 18.53 GB / 24.83 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 20.12.2 - /usr/bin/node
npm: 8.3.0 - /usr/local/bin/npm
bun: 1.0.21 - ~/.bun/bin/bun
Used Package Manager
npm
Validations
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- [X] The provided reproduction is a minimal reproducible of the bug.
I forget what the issue in #54 was, but afaik Jest only takes CJS imports. This package is only published as ESM
Closing this issue. If youre using this in jest tests, you have to explicitly add it was an external module that will require transpilation as shown above since react-timezone-seelct is esm only 🙏