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

nx ng mfe setup not working : 13.2.2 #7862

Closed
moorthyptm opened this issue Nov 24, 2021 · 8 comments
Closed

nx ng mfe setup not working : 13.2.2 #7862

moorthyptm opened this issue Nov 24, 2021 · 8 comments
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@moorthyptm
Copy link

Current Behavior

Once every mfe setup done if I landed into localhost:4200 the app keep reloading

Expected Behavior

it should serve mfe application properly

Steps to Reproduce

yarn create nx-workspace ng-mfe --packageManager=yarn

What to create in the new workspace ...

empty [an empty workspace with a layout that works best for building apps]

Use Nx Cloud? (It's free and doesn't require registration.) ...
Yes Faster builds, run details, GitHub integration. Learn more at https://nx.app

No

cd ng-mfe

Yarn

yarn add -D @nrwl/angular

Yarn

yarn nx g @nrwl/angular:app dashboard --mfe --mfeType=host --routing=true

yarn nx serve dashboard ( working but we have this console erro :Uncaught SyntaxError: Cannot use 'import.meta' outside a module)

Yarn

yarn nx g @nrwl/angular:app login --mfe --mfeType=remote --port=4201 --host=dashboard --routing=true

yarn nx run dashboard:serve-mfe (it keep reloading: port 4200 host application, error: initialization of sharing external failed: ScriptExternalLoadError: Loading script failed.
(missing: http://localhost:4201/remoteEntry.js))

Code URL: https://github.com/moorthyptm/ng-mfe

Note: This issue is not occurring in below version
"@nrwl/angular": "^13.1.3",
"@nrwl/workspace": "13.1.3",

@SandeepThomas
Copy link

Temporary workaround till issue is resolved:

  1. Add scriptType: 'text/javascript' to output to fix import.meta error.
module.exports = {
  output: {
    uniqueName: "dashboard",
    publicPath: "auto",
    scriptType: 'text/javascript'
  }, 
...

Ref: https://webpack.js.org/configuration/output/#outputscripttype

  1. Start the server with --liveReload=false to prevent auto reload loop.

The same issue is being discussed at angular-architects/module-federation-plugin#96

@Coly010
Copy link
Contributor

Coly010 commented Nov 25, 2021

@moorthyptm The workaround suggested by @SandeepThomas should help you get unblocked.
This is actually a bug in Webpack itself and it is currently being worked on webpack/webpack#14827

@leosvelperez leosvelperez added the scope: angular Issues related to Angular support in Nx label Nov 25, 2021
@moorthyptm
Copy link
Author

Temporary workaround till issue is resolved:

  1. Add scriptType: 'text/javascript' to output to fix import.meta error.
module.exports = {
  output: {
    uniqueName: "dashboard",
    publicPath: "auto",
    scriptType: 'text/javascript'
  }, 
...

Ref: https://webpack.js.org/configuration/output/#outputscripttype

  1. Start the server with --liveReload=false to prevent auto reload loop.

The same issue is being discussed at angular-architects/module-federation-plugin#96

Thanks @SandeepThomas its working

@moorthyptm
Copy link
Author

moorthyptm commented Nov 25, 2021

@moorthyptm The workaround suggested by @SandeepThomas should help you get unblocked. This is actually a bug in Webpack itself and it is currently being worked on webpack/webpack#14827

Thanks @Coly010

I will track webpack/webpack#14827 issue

moorthyptm added a commit to moorthyptm/ng-mfe that referenced this issue Nov 25, 2021
@LironHazan
Copy link
Contributor

LironHazan commented Dec 5, 2021

@Coly010 The workaround works for me but I've tested the webpack/webpack#14827 fix and I'm still experiencing that issue , should we wait for an NX update which includes that wp fix actually (v5.64.4)?

experiments: {
    outputModule: true
  },
  plugins: [
    new ModuleFederationPlugin({
      name: "ft1_app",
      library: { type: "module" },
      filename: "remoteEntry.js",
      exposes: {
        './Module': './packages/ft1_app/src/app/remote-entry/entry.module.ts',
      }......
      

@moorthyptm
Copy link
Author

Hi @LironHazan

I hope this maybe help you [exp -> modules are not working in older angular-architects/module-federation-plugin ]

try this:
https://github.com/angular-architects/module-federation-plugin/blob/main/migration-guide.md

or

try this webpack config

https://github.com/moorthyptm/ng-mfe/blob/master/apps/login/webpack.config.js

@Coly010
Copy link
Contributor

Coly010 commented Jan 25, 2022

Nx contains the fix to use ESM. It would be a better experience overall to use the ESM method, however, there will be an error logged to the console about styles.js when running in dev mode. It doesn't affect or break anything. And it doesn't exist in production builds.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

5 participants