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

allCountries undefined in Jest #148

Open
jasonburrows opened this issue Feb 9, 2024 · 2 comments
Open

allCountries undefined in Jest #148

jasonburrows opened this issue Feb 9, 2024 · 2 comments

Comments

@jasonburrows
Copy link

jasonburrows commented Feb 9, 2024

Here's a minimal reproduction:

import { allCountries } from 'country-region-data';

  test.only('countries should be defined', async () => {
    expect(allCountries).toBeDefined();
  });

Result:

    expect(received).toBeDefined()

    Received: undefined

Note that version 2.7.0 of country-region-data does not exhibit this behaviour (I can change nothing but the version and the test passes). Also note that v3.0.0 works correctly in the associated application, it is specifically the Jest test suite where it is undefined (and in the application itself when running in Jest).

Version information:

jest: 29.7.0
country-region-data: 3.0.0
node: 18.15.0

@Nickersona
Copy link

+1 to this issue, but in another context. My project builds a Remix app using vite 5.4.1 and on the server import of the package the value is undefined. Vite is configured in esm server modules, though I'm a bit confused why this would be the problem.

Rolling back to 2.7.0 resolves the issue. I imagine this is a result of adding this to the package.json though specifically why it was included I'm unclear: cac67c8#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R6

@last-partizan
Copy link

Another possible workaround is to add to vitest config:

    alias: {
      // Module definition is bugged:
      // https://github.com/country-regions/country-region-data/issues/148
      'country-region-data': 'country-region-data/dist/data',
    },

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

3 participants