when i run ionic serve -l
i got error like
ENV is not defined
please help me to fix it
when i run ionic serve -l
i got error like
ENV is not defined
please help me to fix it
Please post the whole error output you are getting.
Also post your ionic info output please.
cli packages: (D:\ej\ejohri-spare\node_modules)
@ionic/cli-utils : 1.12.0
ionic (Ionic CLI) : 3.12.0
global packages:
cordova (Cordova CLI) : 7.0.1
local packages:
@ionic/app-scripts : 3.0.0
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.6.1
System:
Android SDK Tools : 26.1.1
Node : v6.10.3
npm : 5.4.2
OS : Windows 7
Misc:
backend : legacy
Error:-
I didnât get any error in command prompt but i got error in browser
ReferenceError: ENV is not defined
at DemoApp.webpackJsonp.384.DemoApp.initializeApp (http://localhost:8100/build/main.js:2574:21)
at new DemoApp (http://localhost:8100/build/main.js:2560:14)
at createClass (http://localhost:8100/build/vendor.js:11303:26)
at createDirectiveInstance (http://localhost:8100/build/vendor.js:11121:37)
at createViewNodes (http://localhost:8100/build/vendor.js:12562:49)
at createRootView (http://localhost:8100/build/vendor.js:12457:5)
at Object.createProdRootView [as createRootView] (http://localhost:8100/build/vendor.js:13145:12)
at ComponentFactory_.create (http://localhost:8100/build/vendor.js:10229:46)
at ComponentFactoryBoundToModule.create (http://localhost:8100/build/vendor.js:3690:29)
at ViewContainerRef_.createComponent (http://localhost:8100/build/vendor.js:10431:62)
Interesting. Your versions are all current.
Can you look at the main.js what it is doing there? What does this ENV do there?
which file you want to see?
Where it complains in the error.
This error line number main.js:2574:21 is same as error line number app.component.ts:64
It meas here
app.component.ts file:-
initializeApp()
{
this.platform.ready().then(() =>
{
this.database = Database.getInstance();
this.cart = Cart.getInstance();
this.menuItems = this.database.parentCategory();
console.log(this.menuItems);
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
});
console.log(ENV);
if (ENV.environment === 'dev')
{
console.log('development');
// Run without the `--prod` flag.
// Any keys defined in `dev.json` will be available on the `ENV` object.
}
else if (ENV.environment === 'prod')
{
console.log('production');
// Run with the `--prod` flag.
// Any keys defined in `prod.json` will be available on the `ENV` object.
}
}
Where does this code come from? It seems that âENVâ is not set.
My app.component.ts file:-
import { Component, ViewChild } from '@angular/core';
import { Platform, MenuController, Nav } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Database, Cart, Category } from '../providers/database';
import { Calendar } from '@ionic-native/calendar';
declare const ENV;
export interface PageInterface
{
title: string;
name: string;
icon?: string;
logsOut?: boolean;
index?: number;
tabName?: string;
detail?: string;
}
@Component
({
templateUrl: 'app.html'
})
export class EjohriApp
{
@ViewChild(Nav) nav: Nav;
database: Database;
cart: Cart;
menuItems: Category[];
// make HelloIonicPage the root (or first) page
rootPage: string;
pages: PageInterface[] = [
{ title: 'Store Visit', name: 'TabsPage', tabName: 'ProfilePage', index: 4, detail: 'my orders' },
{ title: 'Sign out', name: 'SigninPage', tabName: 'SigninPage', index: 2 },
];
constructor(public platform: Platform,public menu: MenuController,public statusBar: StatusBar,public splashScreen: SplashScreen,private calendar: Calendar)
{
this.rootPage = 'SigninPage';
this.initializeApp();
}
initializeApp()
{
this.platform.ready().then(() =>
{
this.database = Database.getInstance();
this.cart = Cart.getInstance();
this.menuItems = this.database.parentCategory();
console.log(this.menuItems);
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
});
console.log(ENV);
if (ENV.environment === 'dev')
{
console.log('development');
// Run without the `--prod` flag.
// Any keys defined in `dev.json` will be available on the `ENV` object.
}
else if (ENV.environment === 'prod')
{
console.log('production');
// Run with the `--prod` flag.
// Any keys defined in `prod.json` will be available on the `ENV` object.
}
}
ionViewDidLoad()
{
this.calendar.createCalendar('MyCalendar').then(
(msg) => { console.log(msg); },
(err) => { console.log(err); }
);
}
toggleItems(cat: Category)
{
cat.parentShow = !cat.parentShow;
this.menuItems.forEach(item =>
{
if (item.id !== cat.id)
{
item.parentShow = false;
}
})
}
openPage(page)
{
// close the menu when clicking a link from the menu
this.menu.close();
// navigate to the new page if it is not the current page
if(page.name === 'SigninPage')
{
this.nav.setRoot(page.name);
}
else if(page.name === 'CategoriesPage')
{
this.nav.setRoot(page.name);
}
else
{
this.nav.setRoot('CategoriesPage');
}
}
categories(menuItem: Category, child: Category)
{
this.menu.close();
this.nav.setRoot('TabsPage', { tabIndex: 0, parent: menuItem, detail: child.name });
}
}
My dev.json file:-
{
âenableLoggingâ: true,
âapiServerUrlâ: ââhttp://example.com/apiââ
}
My prod.json file:-
{
âenableLoggingâ: true,
âapiServerUrlâ: ââhttp://prod.example.com/apiââ
}
this two file is under folder named as env
and this env folder is outside the src folder
Please edit your post, it is not very readable at the moment.
Use the </> button above the input field to format your code, command line output or error message (select the text first, then click the button or wrap it in ``` manually). Check the preview if it looks better. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.
Yeah but where did you get the idea to add that code this way? Is this from a Ionic starter or some other project? Or you own logic you wrote yourself?
Thanks for giving me guide for formatting code
Code comes from some other project
i bought project from ionic market
This code doesnât really do anything but log - canât you just remove it?
Now what should i do?
please advice me
Talk to whoever sold you this code and tell them to either help you make it work or give you your money back.
This is not a right solution because till now itâs work fine
after upgrading app-scripts and angular version to latest i got this error
Please try to look at this from the perspective of volunteer community posters. Would you not find it incredibly frustrating to be asked to provide free support for somebody elseâs paid product? This is the responsibility of whoever is profiting from selling this code, and nobody elseâs.
Sorry for telling you
This is not a right solution
You should to what I wrote: Remove the code.