joeldenning / single-spa-es5-angularjs

A single-spa example with an es5 angularjs app
MIT License
12 stars 7 forks source link

Getting died in status LOADING_SOURCE_CODE: "does not export an unmount function or array of functions" #1

Closed tarunnav closed 5 years ago

tarunnav commented 5 years ago

I have root app which is basic app using singlespa and loading the es5-app.js which is hosted on different port. When I lazy load es5-app.js I get below error

Application 'es5-app' died in status LOADING_SOURCE_CODE: "does not export an unmount function or array of functions"

Could you help me how do export bootstrap, mount and unmount functions from my child app

joeldenning commented 5 years ago

Did you get this error as a fork of single-spa-es5-angularjs? If so, the way to export the lifecycle functions is by creating a global variable with those functions in an object. See https://github.com/joeldenning/single-spa-es5-angularjs/blob/master/es5-app.js#L2 for how this is happening in this example repo

hiaparna commented 5 years ago

I am getting the same error, however I am using single-spa in react framework. Any inputs on how to fix this ? thx

joeldenning commented 5 years ago

Hi @hiaparna, could you paste some code showing your loading functions? Are you using the recommended setup with System.import()? Or just webpack import()?

This error means that your loading function returned a promise that resolved with an object that did not have the single-spa lifecycle functions on it. Loading functions must resolve to an object that has bootstrap, mount, and unmount functions on them.

hiaparna commented 5 years ago

Hi @joeldenning, I am sharing the demo application build using single-spa. I have added 2 applications and both are in react dashboard and navbar. It works fine in development. However, when we build it and deploy it in nginx, it shows error in console : Uncaught SyntaxError: Unexpected token <. Repo: https://github.com/hiaparna/single_spa_react

hiaparna commented 5 years ago

I also tried https://github.com/joeldenning/simple-single-spa-webpack-example example in production mode and it gives the same error as : Uncaught SyntaxError: Unexpected token < for common-dependencies and root-application

chrisbrooks commented 5 years ago

@hiaparna you need to use AMD targetLibrary in webpack. output: { library: 'blah', libraryTarget: 'amd',

joeldenning commented 5 years ago

you need to use AMD targetLibrary in webpack. output: { library: 'blah', libraryTarget: 'amd',

Yep, or even better you can use libraryTarget: 'system' if you're using SystemJS. Also, please follow the instructions in the following links, which should get your webpack config fully up and running:

https://single-spa.js.org/docs/faq.html#code-splits https://single-spa.js.org/docs/faq.html#create-react-app