Skip to content
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

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

Closed
3 tasks done
jarvjani opened this issue Jul 16, 2024 · 2 comments
Closed
3 tasks done

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

jarvjani opened this issue Jul 16, 2024 · 2 comments
Assignees

Comments

@jarvjani
Copy link

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 #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

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@ndom91 ndom91 self-assigned this Jul 17, 2024
@ndom91
Copy link
Owner

ndom91 commented Jul 23, 2024

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

@ndom91
Copy link
Owner

ndom91 commented Feb 12, 2025

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 ndom91 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants