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

[BUG] Module federation breaks in typescript when trying to import react #947

Closed
josejulio opened this issue Feb 4, 2021 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@josejulio
Copy link
Member

Describe the bug

I get the following error when loading the page, nothing else loads:

Uncaught (in promise) Error: Shared module is not available for eager consumption: webpack/sharing/consume/default/react/react
    at Object.__webpack_modules__.<computed> (consumes:137)
    at __webpack_require__ (bootstrap:21)
    at fn (hot module replacement:61)
    at Module../src/bootstrap-dev.js (App.js:43)
    at __webpack_require__ (bootstrap:21)
    at fn (hot module replacement:61)
    at entry-dev.tsx:21

To Reproduce

I created a reproducer from the frontend-starter-app

Steps to reproduce the behavior:

  1. Clone frontend-app-starter
  2. Install typescript
  3. Rename entry-dev.js to entry-dev.tsx and add a tsconfig file
  4. Start and open in browser
  5. See error in console

Or instead of steps 1-4 use this commit: RedHatInsights/frontend-starter-app@92ea132

Expected behavior
It should work show the starter application

Desktop (please complete the following information):

  • OS: Fedora
  • Browser Chrome
  • Version Version 87.0.4280.66 (Official Build) (64-bit)

Additional context
There should be some step for the ts/tsx files that is missing in the config. Any hint on what to look would be appreciated.

@josejulio josejulio added the bug Something isn't working label Feb 4, 2021
@josejulio
Copy link
Member Author

Looks like having the entry files as js does the trick.

entry-dev.js

import('./bootstrap-dev');

bootstrap-dev is a typescript file.

I'll keep testing and will close this issue if everything seems fine.

@rajsenthil
Copy link

I got struck for many days until I saw this message. Thanks.

@josejulio
Copy link
Member Author

Glad that it was useful. I ran into other issues (resolved by now), so let me know and I might be able to help.

@chrispcode
Copy link

Hey guys, I was able to solve this by using this typescript configuration:

{
  "include": ["src/**/*"],
  "compilerOptions": {                   
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "jsx": "react",
    "strict": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
  }
}

module to esnext and moduleResolution to node is what I think did the trick!

@chrispcode
Copy link

and yes, my bootstrap file is called: bootstrap.tsx
and here is my request sequence:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants