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

Can't add react application in angular as parcel app #335

Closed
bullypb23 opened this issue Feb 4, 2021 · 5 comments
Closed

Can't add react application in angular as parcel app #335

bullypb23 opened this issue Feb 4, 2021 · 5 comments

Comments

@bullypb23
Copy link

bullypb23 commented Feb 4, 2021

Hi,

I am trying to use a single spa framework in my project and I want to build react and angular parcel apps and use them in angular and react applications as parcels. I have a problem with adding react application to angular as parcel app and I keep getting this error.

image

My angular application code where I want to use this parcel app.

image

image

The other way around I succeeded but I keep getting this error for this case. Would appreciate help regarding my issue.

@filoxo
Copy link
Contributor

filoxo commented Feb 4, 2021

The problem is that you're using a relative import (import { bootstrap, mount, unmount } from '../../../react-test/src/thingsolver-react-test'). This is not how Parcels work.

First, you cannot import a React component directly into your Angular application. By using a relative import, that React component is being pulled into your Angular application and put through Angular's Webpack build pipeline which does not support React. Instead, that Parcel needs to be built and served separately in order to be able to resolve it at runtime using SystemJS and cross microfronted imports.

Second, your Parcel is already exporting the lifecycles so you to not need to import the individual lifecycles to create this object. Just do import * as thingsolverReactTestParcelConfig from 'thingsolver-react-test'.

@bullypb23
Copy link
Author

Thank you for your response. Now I get this error. Do I need to change webpack config for my route angular application?

image

@filoxo
Copy link
Contributor

filoxo commented Feb 4, 2021

You need to do two things:

  1. Ensure that that package is in the externals array of your webpack config so that webpack knows that it should not try to bundle that module into your application, and
  2. Obtain types for it somehow so that TypeScript will allow it to compile; the options for this are described in these issues

You can either enumerate each package to be marked as external or use a regex like our other base webpack configs do. I'm not super familiar with how Angular allows devs to modify their webpack configs, but our docs have an example of adding to the externals here: https://single-spa.js.org/docs/ecosystem-angular/#inter-app-communication-via-rxjs

@bullypb23
Copy link
Author

Thank you @filoxo very much, you solved my problem. If I would have any questions in the future regarding this same problem I would ask them here.

@filoxo
Copy link
Contributor

filoxo commented Feb 4, 2021

Glad you were able to get it working! I'm going to ahead and close this issue. Feel free to reopen if you encounter more bugs/issues, and you can always ask questions in the Slack channel too.

@filoxo filoxo closed this as completed Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants