ibitcy / eo-locale

šŸŒInternationalize React apps šŸ‘”Elegant lightweight library based on Internationalization API
https://eo-locale.netlify.com/
MIT License
348 stars 12 forks source link

Need to use 'fullySpecified' Webpack 5 config to use this library #84

Closed karol-f closed 2 years ago

karol-f commented 2 years ago

In .mjs files or .js files with a package.json with "type": "module" imports need to be fully specified. This means you need to have an extension.

https://github.com/webpack/webpack/issues/11467#issuecomment-691702706

Solution is to use (not working with Next.js with esmExternals):

{
  test: /\.m?js/,
  resolve: {
    fullySpecified: false
  }
}

It's better to align this lib and not enforce its users to have to use Webpack config and avoid such errors:

error - unhandledRejection: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '[...]/node_modules/react-dom/server' imported from [...]/node_modules/@eo-locale/react/lib/index.js
Did you mean to import react-dom/server.js?
    at new NodeError (node:internal/errors:371:5)
    at finalizeResolution (node:internal/modules/esm/resolve:416:11)
    at moduleResolve (node:internal/modules/esm/resolve:932:10)
    at defaultResolve (node:internal/modules/esm/resolve:1044:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

We should modify https://github.com/ibitcy/eo-locale/blob/master/packages/react/src/index.tsx#L9 to have extension.

Tested on: