I’m new to Ionic and Ionic 2.0. I created a simple hello world app. When I load with ionic serve -l, though the page loads correctly, when I take a look at console, I find the error… “Uncaught ReferenceError: ionic is not defined” … How do I fix this ? Looking up online seems to be that I’m missing a reference to ionic.bundle.js …but, that seems to be related to ionic 1.x. Please let me know how I can resolve this error. Thanks.
Can you provide context to where in your application you are receiving the error? It sounds like a bad import, so I’d make sure that your imports are correct and referencing what you think they are.
I am running into the same issue. I have just updated to ionic 2 (2.0.0-beta.15) and did a
ionic start testApp --v2 to create the default tabs app.
After that I did an
ionic serve --lab. I can see the first tab of the app with content but the other tow tabs are empty. i see the same “Uncaught ReferenceError: ionic is not defined”. I do have bundle.js included and the browser says it loaded the file successfully.
The reference error occurs in the
script tag code, that got injected by ionic into the index.html file:
... <body> <script src="cordova.js"></script> <script src="build/js/app.bundle.js"></script> <ion-app></ion-app> <script> ionic && ionic.Platform && ionic.Platform.setPlatform("android"); </script> </body> ...
Seems like the default app does have tabs, but it does not have content in tabs 2 and 3. That was my bad.
I found this one https://github.com/driftyco/ionic2/issues/763 which fixes it for non --lab. So maybe we just have to wait for the next release.
Sorry for delayed response. I’m not sure the source of the error… But, ignoring this error is the approach I took. I like no warnings/errors scenario though.
I’m seeing this too when running
ionic serve --lab on a newly created Ionic 2 project.
Any progress on this issue so far?
Same here. While the ignoring of error works i.e. no impact on the app, it requires at least 2 clicks for every app refresh (live reload) and is becoming annoying.
Would sincerely appreciate the work around and/or fix
I have tried going to:
As she mentioned: Ionic 2 - Uncaught ReferenceError: ionic is not defined
So, now I have no this error.
To summarise it seems the error happens when using the
-l flag for the lab view when serving the app, am i right?
Partially, it does when you go to lower-cased address. But
ionic went to be defined only when you go to
?ionicPlatform, so no error.
However there is a misspelling in Ionic CLI itself, when you serve application for specified platform or with “lab”, e. g. by typing
ionic serve -t android/ios or
ionic serve -l, it finally leads to
Workaround: you can type
ionic serve -b, wait for
Running dev server message and then open it manually:
http://localhost:8100/?ionicPlatform=android through a bookmark. But you still may ignore this error
ionic is not defined, cause people don’t see any damage after it.
I don’t use those options so have never seen those errors, i mostly do
ionic serve -sc,
ionic run (android|ios) or at least
ionic emulate ios.