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

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

Closed
salixor opened this issue Jan 18, 2023 · 14 comments · Fixed by #1350
Closed

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

salixor opened this issue Jan 18, 2023 · 14 comments · Fixed by #1350
Labels

Comments

@salixor
Copy link

salixor commented Jan 18, 2023

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

  • jsLingui version 3.16.0
  • Babel version 7.20.12
@Martin005 Martin005 added the bug label Jan 18, 2023
@andrii-bodnar
Copy link
Contributor

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

@semoal
Copy link
Contributor

semoal commented Jan 18, 2023

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
Copy link
Contributor

@semoal thank you! There is an explanation of why it was done in such way - #1343 (comment)

what do you think about that?

@thekip
Copy link
Collaborator

thekip commented Jan 18, 2023

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

@thekip
Copy link
Collaborator

thekip commented Jan 18, 2023

You probably running this on a server side?

@Martin005
Copy link
Contributor

Martin005 commented Jan 18, 2023

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

@thekip
Copy link
Collaborator

thekip commented Jan 18, 2023

@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
Copy link
Collaborator

thekip commented Jan 18, 2023

@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
Copy link
Collaborator

thekip commented Jan 18, 2023

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
Copy link

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

@thekip
Copy link
Collaborator

thekip commented Jan 19, 2023

In react-native it's caused by this facebook/metro#670

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

@DavidAPears
Copy link

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
Copy link
Author

salixor commented Jan 19, 2023

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 (webpack/webpack#9509), but it does not look like the root cause

@explodingcamera
Copy link

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;

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

Successfully merging a pull request may close this issue.

8 participants