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

Module not found: Error: Package path ./locale-data is not exported from package /node_modules/@formatjs/intl-displaynames (see exports field in @formatjs/intl-displaynames/package.json) #4127

Closed
alexeymolchan opened this issue Jun 6, 2023 · 6 comments
Labels

Comments

@alexeymolchan
Copy link

alexeymolchan commented Jun 6, 2023

@formatjs/intl-displaynames: ^6.4.0,
react-intl: ^6.4.3,
typescript: ^5.1.3,
webpack: ^5.85.1"

tsconfig options:

"compilerOptions": { "module": "esnext", "moduleResolution": "node", }

https://formatjs.io/docs/polyfills/intl-displaynames#dynamic-import--capability-detection

after latest update dynamic loading of locale-data doesn't work.

the same error for @formatjs/intl-numberformat and @formatjs/intl-datetimeformat.

i suppose this is related to wildcard exports property in package.json.

"./locale-data/*": { "types": "./locale-data/*.d.ts", "default": "./locale-data/*.js" },
error thrown only when using dynamic import, import ar from "@formatjs/intl-displaynames/locale-data/ar"; works fine

@longlho
Copy link
Member

longlho commented Jun 6, 2023

please pin to the previous versions while we're investigating
cc @pyrocat101

@chenp1204
Copy link

The same error too,

@jlowcs
Copy link

jlowcs commented Jun 7, 2023

With this in the package.json file, it seems to work for me:

    "./locale-data": {
      "default": "./locale-data"
    },

Also, adding this (with .js extension) for backward compatibility might be a good idea:

    "./locale-data/*.js": {
      "types": "./locale-data/*.d.ts",
      "default": "./locale-data/*.js"
    },

@webda2l
Copy link

webda2l commented Jun 8, 2023

Same with the latest release, about intl-listformat and my Component:

Import trace for requested module:
./components/_shared/_slice/PhilosophySlice.tsx
./pages/pricing/studio.tsx
- wait compiling /_error (client and server)...
- error ./components/_shared/FormattedList.tsx:39:8
Module not found: Package path ./locale-data is not exported from package /home/david/Works/OLYBe/website/node_modules/@formatjs/intl-listformat (see exports field in /home/david/Works/OLYBe/website/node_modules/@formatjs/intl-listformat/package.json)
  37 |   // Load the polyfill 1st BEFORE loading data
  38 |   await import('@formatjs/intl-listformat/polyfill-force')
> 39 |   await import(`@formatjs/intl-listformat/locale-data/${unsupportedLocale}`)
     |        ^
  40 | }
  41 | 

https://nextjs.org/docs/messages/module-not-found
import { shouldPolyfill as shouldPolyfillGetCanonicalLocales } from '@formatjs/intl-getcanonicallocales/should-polyfill'
import { IntlListFormatOptions } from '@formatjs/intl-listformat'
import { shouldPolyfill as shouldPolyfillListFormat } from '@formatjs/intl-listformat/should-polyfill'
import { shouldPolyfill as shouldPolyfillLocale } from '@formatjs/intl-locale/should-polyfill'
import React from 'react'
import { FormattedList as BaseFormattedList, useIntl } from 'react-intl'

type IProps = IntlListFormatOptions & {
  value: readonly React.ReactNode[]
}

export const FormattedList: React.FC<IProps> = (props) => {
  const { locale } = useIntl()

  if (!props.value) return null

  polyfill(locale)

  return <BaseFormattedList {...props} />
}

const polyfill = async (locale: string) => {
  // This platform already supports Intl.getCanonicalLocales
  if (shouldPolyfillGetCanonicalLocales()) {
    await import('@formatjs/intl-getcanonicallocales/polyfill')
  }
  // This platform already supports Intl.Locale
  if (shouldPolyfillLocale()) {
    await import('@formatjs/intl-locale/polyfill')
  }

  const unsupportedLocale = shouldPolyfillListFormat(locale)
  // This locale is supported
  if (!unsupportedLocale) {
    return
  }
  // Load the polyfill 1st BEFORE loading data
  await import('@formatjs/intl-listformat/polyfill-force')
  await import(`@formatjs/intl-listformat/locale-data/${unsupportedLocale}`)
}

No success with #4127 (comment)

No errors with:

        "@formatjs/intl-getcanonicallocales": "2.2.0",
        "@formatjs/intl-listformat": "7.2.2",
        "@formatjs/intl-locale": "3.3.0",
        "react-intl": "6.4.2",

pyrocat101 added a commit that referenced this issue Jun 12, 2023
…t-parser,@formatjs/intl-displaynames,@formatjs/intl-listformat,intl-messageformat,@formatjs/ecma402-abstract,@formatjs/intl-numberformat,@formatjs/icu-skeleton-parser): Revert esm conditional exports (#4129)

The ESM export chanegs are not properly tested and therefore broke in various scenarios.

Fixes #4128, #4127, #4126

This reverts commit e0d593c.
@pyrocat101
Copy link
Member

Sorry for breaking your build. The newer version should include the ESM export revert. See also: #4126 (comment)

@webda2l
Copy link

webda2l commented Jun 12, 2023

Sorry for breaking your build. The newer version should include the ESM export revert. See also: #4126 (comment)

No worries, thanks for your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants