Changing location of js/app.js

I’ve reworked the structure of my app to be more focussed on modules but in doing so, I’ve moved the location of js/app.js

Now when I install things like ionic-service-core, terminal gives me a warning:

solitaire:gamebeacon james$ ionic add ionic-service-core
Bower component installed - ionic-service-core
ERROR:  { [Error: ENOENT, open './www/js/app.js'] errno: -2, code: 'ENOENT', path: './www/js/app.js' }
Is your app declaration contained in 'app.js'?

I’m hoping this is just a case of having to update some config somewhere but I’m struggling to find out where that is. Anyone know?

1 Like

So where did you move your app.js to? From www to another root directory?

I did the same thing (moved my sources to “src” and used “www” as the output directory for Cordova builds).
All I had to do then is in your “ionic.project” file I had to put:

“documentRoot”: “src”

It’s not finalised yet but for now, it’s here:
It’s still under www but in a different sub folder.

Your change doesn’t work because the app root hasn’t actually changed - just the location of the app.js file.

Not sure how to do that.

I also used a very different (more modular) directory structure (with sources under “src” and Cordova builds going under “www”), but the location of my ‘app.js’ is still the same relative to my “root” directory (src).

In case you are interested you can see my structure here.

Take a look at these docs for the services

ionic app is trying to inject any service you add into your app.js. Right now it’s not possible with custom locations, but you can turn it off. Custom file structures are something we’re adding down the road.

1 Like

Ah ok cool. I knew what it was trying to do but hoped there was a config key to define the custom location. Nevermind though, now I know what it’s doing, I can restructure to fit it’s needs as well as mine :slight_smile:

Anything new on this? I’m having the same issue.

1 Like

Any progress on this?

Will it work if I simply move my app.js file to “www/js/app.js” JUST for the install (when run ionic add ionic-platform-web-client)?

If I then move it back to my original location (eg www/xyz123/)- will it function fine?

Hi, did you try that option? Did it work?