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

Error while packaging a JavaScript file not in a subfolder #66

Closed
ahadcove opened this issue Jan 5, 2017 · 14 comments
Closed

Error while packaging a JavaScript file not in a subfolder #66

ahadcove opened this issue Jan 5, 2017 · 14 comments
Assignees
Labels

Comments

@ahadcove
Copy link

ahadcove commented Jan 5, 2017

Im getting this error after I package my app and then try to run it:

Uncaught Exception:
Error: Asked for ...Path/App.app/Contents/Resources/app/main.js but it was not precompiled!
    at FileChangedCache.getHashForPathSync (...Path/out/App-darwin-x64/App.app/Contents/Resources/app/node_modules/electron-compile/lib/file-change-cache.js:249:15)

Any idea onto why this is happening?

@MarshallOfSound
Copy link
Member

  • Does it work with a simple electron-forge start
  • How are you requiring main.js, is it your entry point?

@MarshallOfSound MarshallOfSound added bug help wanted blocked/upstream Issues blocked by upstream bugs and removed help wanted labels Jan 5, 2017
@ahadcove
Copy link
Author

ahadcove commented Jan 5, 2017

Well when I use START the same thing is happening when I was using electron-packager: A static index.html with the loading text that I have when starting up my electron app for the first time.
It suppose to route to my home as soon as it starts though as it does when I have a simple ng build.

I am requiring main.js as my entry point.

in my Package.json the main field is:

"main":"main.js"

@malept malept changed the title Erro while packaging. main.js was not precompiled Error while packaging. main.js was not precompiled Jan 5, 2017
@MarshallOfSound
Copy link
Member

@ahadcove Your JS files must be inside a directory (not just sitting in the top level of your app). I.e. If you move main.js to be somewhere like src/main.js and update your package.json accordingly the packaged version will work.

/cc @malept We should probably catch this issue ourselves

@malept malept changed the title Error while packaging. main.js was not precompiled Error while packaging a JavaScript file not in a subfolder Jan 5, 2017
@malept malept removed the blocked/upstream Issues blocked by upstream bugs label Jan 5, 2017
@ahadcove
Copy link
Author

ahadcove commented Jan 5, 2017

I switched the directories and everything and it does get past the error. I am still running into the static index.html though.

For some reason, I just can't figure out how to make my App work all packaged up

@MarshallOfSound
Copy link
Member

MarshallOfSound commented Jan 5, 2017

@ahadcove I am not too familiar with the intricacies of Angular 2, can you explain what you mean by "static index.html". I don't quite understand the issue you are having.

@ahadcove
Copy link
Author

ahadcove commented Jan 5, 2017

Well my original problem was that when I run my project with ng build or ng serve it works 100% all the routers and everything just works.
It was when I started trying to package up my app with electron-packager, builder, and forge where I get the routes no longer working. Instead of loading up the Index.html then immediately navigating to my home component it stays at the index.

@MarshallOfSound
Copy link
Member

This sounds familiar from an Electron issue. I believe it is due to how in Electron your Angular app is served from a file:// url which angular routers do not like or expect.

@ahadcove
Copy link
Author

ahadcove commented Jan 5, 2017

Hmmm That sounds like where my problem may lie, but Why would it work with ng serve and build?

@MarshallOfSound
Copy link
Member

@ahadcove ng serve runs a localhost server I believe, so it will be served over something like http://localhost:1234

@ahadcove
Copy link
Author

ahadcove commented Jan 5, 2017

Okay so it may have something to do with Hash Locations or something
I will dig a little deeper. I may come back to forge later when I figure this out. Thanks for everything

@MarshallOfSound
Copy link
Member

@ahadcove FWIW this is not a -forge or -packager issue, it is purely an issue with Angular 2 in Electron in general.

This might help you out
electron/electron#6799 (comment)

It looks like you need

document.write('<base href="file://' + __dirname + '/"/>');

To use a router in Angular in Electron

@ahadcove
Copy link
Author

ahadcove commented Jan 5, 2017

Yes, I have that in my index.html already. That is what get's routers working. I have a fully working angular 2 Electron app already, its just when I package it with anything it no longer functions how it should be

@MarshallOfSound
Copy link
Member

Is the app public, I'm happy to dive into it and see what's going on?

@ahadcove
Copy link
Author

ahadcove commented Jan 5, 2017

Sadly, it's not. I'm going to keep picking away at it though. I definitely like the idea of forge though so I may be back when I get this figured out. Thank you for everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants