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

Loading angular apps (different versions) inside root appliatin with singleSpaEntry exposed inside each app #50

Open
sri1980 opened this issue Sep 10, 2018 · 7 comments

Comments

@sri1980
Copy link

sri1980 commented Sep 10, 2018

I am working to build an app to load different version angular apps using loader (root application) approach.

app1 -> angular 1.x
app2 -> angular 4 (using angular-cli)
app3 -> angular 6 (using angular-cli)

Each app will have singleSpaEntry.ts with mount, unmount (lifecyle methods). All these apps are managed and implemented by different teams.

Registering application

singleSpa.registerApplication(name, () => SystemJS.import(appURL), hashPrefix(hash));
   
 appURL -> http://<hostname>:port//singleSpaEntry.js

Can you please let me know, is there any format or dependencies i need to follow to compile singleSpaEntry.ts?

Getting below error while trying to access the app.

Uncaught Error: Application 'app6' died in status LOADING_SOURCE_CODE: Unexpected token <

Please find the example app created at https://github.com/naresh217/single-spa

@me-12
Copy link
Owner

me-12 commented Sep 26, 2018

The Angular CLI does not compile the App as UMD module. And therefore system.js in the portal app can't load it.

You need a custom webpack.config.js which defines all the necessary steps to compile the Angular app with singleSpaEntry.js as entry file to a UMD module.

Take a look in the folder "app5Angular" which is an Angular 6 app that works.

@adrianlemess
Copy link

So, if we have a team working with a project generate with angular-cli, we need to eject the build to do with webpack? it's posible to mantain both configurations (angular-cli and webpack.config) in the same project?

@kgamalseif
Copy link

Also, I am getting the same issue...
Uncaught Error: Application 'app6' died in status LOADING_SOURCE_CODE: Unable to dynamically transpile ES module A loader plugin needs to be configured via SystemJS.config({ transpiler: 'transpiler-module' }). Instantiating http://localhost:9000/app6/singleSpaEntry.js Loading /app6/singleSpaEntry.js

Is there any way to load angular 6 cli app with singleSpaEntry.js?
appreciate your help...

@fireappsAdmin
Copy link

Did you find a way around this? I am also having this issue.

@maciej-w
Copy link

maciej-w commented Oct 24, 2018

@fireappsAdmin @kgamalseif
This question has already an answer, you need to eject your apps (if possible) and then create a custom webpack.config -> Take a look in the folder "app5Angular" which is an Angular 6 app that works. Or have a look below.

@adrianlemess
I created an Angular 6 app (which doesn't have the ng eject option anymore and used "@angular-builders/custom-webpack": "^2.5.4", then in my angular.json you have to update the build options like this:
"build": { "builder": "@angular-devkit/build-angular:browser",

You'll find more info at the package website. Anyways if you place just the webpack.config.js in your root folder and add the npm run watch:portal from the example Angular apps it'll work and serve the app to the portal.

@kgamalseif
Copy link

@maciej-w
Thanks for reply, I also used the app5Angular as a guide, and unfortunately got the same error.

I am able to browse my app after npm run watch:portal as below, but got the LOADING_SOURCE_CODE error when browsing using portal.

image

Appreciate your help...

@maciej-w
Copy link

@kgamalseif - I can see that this is a different app than form the example. To me it looks like your module is not building correctly, without looking at the code I'm not able to help. Please follow this to check if your code follows best practices: Angular AOT

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

6 participants