react-timezone-select icon indicating copy to clipboard operation
react-timezone-select copied to clipboard

Create React App: Jest tests fails to find the module declaration

Open jarvjani opened this issue 1 year ago • 1 comments

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 image

Steps to reproduce: unzip import-error.zip cd import-error npm install npm test

Expected: Test runs fine Actual result: Test fails image 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)/"
    ]
  },
 

image

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.

jarvjani avatar Jul 16 '24 09:07 jarvjani

I forget what the issue in #54 was, but afaik Jest only takes CJS imports. This package is only published as ESM

ndom91 avatar Jul 23 '24 17:07 ndom91

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 🙏

ndom91 avatar Feb 12 '25 13:02 ndom91