lingui / js-lingui

🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
https://lingui.dev
MIT License
4.32k stars 368 forks source link

Cannot find module '@lingui/core/compile' #1347

Closed salixor closed 1 year ago

salixor commented 1 year ago

Describe the bug Since release 3.16.0, the error "Cannot find module '@lingui/core/compile' from 'node_modules/@lingui/core/build/cjs/index.js'" pops up. I'm unsure if it is an issue with my setup, or it is related to the global import of "compile" in lingui/core.

To Reproduce No particular steps.

Expected behavior N/A

Additional context

andrii-bodnar commented 1 year ago

@thekip might it somehow be related to the recent changes in the build process?

semoal commented 1 year ago

This line is wrong: https://github.com/lingui/js-lingui/blob/main/packages/core/src/i18n.ts#L4 Since we don't do ts-alias or something like that after build for replacing local references, when compiled this is not going to get resolved.

This should be ../compiler instead

andrii-bodnar commented 1 year ago

@semoal thank you! There is an explanation of why it was done in such way - https://github.com/lingui/js-lingui/pull/1343#discussion_r1072439050

what do you think about that?

thekip commented 1 year ago

Looks like lingui/core/compile doesn't work in cjs environment for some reason. I will take a look

thekip commented 1 year ago

You probably running this on a server side?

Martin005 commented 1 year ago

@thekip Also, the Bundlephobia returns EntryPointError for the new versions of @lingui/core and @lingui/cli, but other packages are okay :thinking:

thekip commented 1 year ago

@salixor could you provide more context. I tried to reproduce but with no luck.

Was it run on the server or not, version of nodejs, if bundler was used name and version of the bundler.

Or... the minimal repo

thekip commented 1 year ago

@Martin005 i quickly investigated issue with bundlephobia but didn't find a root cause. All entries in package.json pointing into right places. I also compared with other packages and everything seems fine. Need to dig deeper into the bundlephobia sourcecode or just create an issue on theirs repo.

thekip commented 1 year ago

Actually, @lingui/cli indeed has an wrong entrypoint. It points to the ./build/index.js which is not exists (as far as i remember it was the same before my refactorings). But actually it should not be directly accessed in consumers code. Only @lingui/cli/api is exposed. So issue only with @lingui/core

tolgahan-arikan commented 1 year ago

hey there @thekip, had the same issue on React Native, rolled back to 3.15.0 for now.

thekip commented 1 year ago

In react-native it's caused by this https://github.com/facebook/metro/issues/670

I exposed cjs entry from @lingui/core for runtimes which doesn't support exports field. Let's check, will it help.

DavidAPears commented 1 year ago

Morning! Since yesterdays release 3.16.0, we also get the error "Cannot find module '@lingui/core/compile' from 'node_modules/@lingui/core/build/cjs/index.js'

Currently no way to work around this issue.

salixor commented 1 year ago

Hey, thanks a lot for looking into this ! Here are some additional infos.

This exact error message happens in our unit tests (jest@26.6.3 + babel-jest@24.9.0 + node@14.21.2).

We also have the following error when trying to build, serve the application, or run basically any command via gulp : "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './api/compile' is not defined by "exports" in <path>/node_modules/@lingui/cli/package.json".

We do use webpack4, which seems as react-native not to support the exports field (https://github.com/webpack/webpack/issues/9509), but it does not look like the root cause

explodingcamera commented 1 year ago

This workaround is working for me (react-native with expo) metro.config.json

const { getDefaultConfig } = require("expo/metro-config");
const config = getDefaultConfig(__dirname);

// https://github.com/facebook/metro/issues/670 - this is a workaround for the issue
config.resolver.resolveRequest = (context, moduleName, platform) => {
  if (moduleName.startsWith("@lingui/core/compile")) {
    moduleName = moduleName.replace(
      "@lingui/core/compile",
      "@lingui/core/build/cjs/compile.js"
    );
  }
  return context.resolveRequest(context, moduleName, platform);
};

module.exports = config;