Beej126 / single-spa-systemjs-cra2.1-ts-no-eject

single-spa sample with CRA2.1, Typescript and webpack AMD module for SystemJS WITHOUT EJECTING
MIT License
16 stars 3 forks source link

Uncaught ReferenceError: define is not defined #2

Closed itsweliton closed 5 years ago

itsweliton commented 5 years ago

Hi @Beej126, it's me again 😅

I'm facing some trouble with this s-spa with cra. I have a set up exactly as yours but using .js instead of .ts (even the same react-scripts version)

however, when I try to run my subproject I got Uncaught ReferenceError: define is not defined . Have you faced anything like this? any idea?.

I saw on StackOverflow that I should import Requirejs to my project, but when I tried that, the application wouldn't load, only showing a blank page and no errors on the console.

Beej126 commented 5 years ago

I kinda remember running into that while I was beating my head to get webpack config’d to output the right module format to be systemJs compatible... “rescripts” was a real breakthrough for me to be able to override CRA’s native webpack module format to “AMD” so that systemJs was able to consume.

My best advice (admittedly not a targeted answer) is leverage the sample as a known working scenario that you can incrementally diverge from... get the sample running as is, see how the JS bundles wind up looking in that happy path and then mirror that in your preferred alternative approach

I get not wanting to take on the additional complexity of TS vs plain jane JS, but i would encourage you to embrace TS if you’re on the fence... it seems very likely to stick around, it’s got solid big vendor support in all 3 big camps - MSFT, Facebook React and the native choice in Google’s angular infrastructure

itsweliton commented 5 years ago

I'm aware of the TS extensive use, and I plan to change the project soon, but now, I couldn't do it.

So, I end up finding the main problem, actually this error happens because when you try to access the project's URL, it's going to load the project without the systemJS, but only with webpack, and therefore it doesn't work. Once I try to access from the s-spa env, it works properly (once it's using the systemjs)

Now I'm facing the LOADING_SOURCE_CODE: "does not export an unmount function or array of functions error event with the .default as you explained in README.md. I'm not sure what is triggering it, but I'll keep digging it.

Thanks for your help @Beej126!