ionic-environment-variables icon indicating copy to clipboard operation
ionic-environment-variables copied to clipboard

Can not find '@app/env' when running 'ionic cordova build ios'

Open stevenwaskey opened this issue 8 years ago • 8 comments

Ionic fails to build ios application stating that it can not locate the @app/env module. Reluctant to create what is almost a duplicate ticket, I have yet to be able to get to the bottom of this.

Command ionic serve -l works without exception.

Command ionic cordova build ios fails with following log & error

[13:12:15]  typescript: src/app/app.module.ts, line: 7 
            Cannot find module '@app/env'. 

       L6:  import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner';
       L7:  import { ENV } from '@app/env';

[13:12:15]  typescript: src/pages/scanner/scanner.ts, line: 5 
            Cannot find module '@app/env'. 

       L4:  import { AuthenticationService } from '../../services/authentication/authentication-service';
       L5:  import { ENV } from '@app/env';

[13:12:15]  typescript: src/services/authentication/authentication-api.ts, line: 5 
            Cannot find module '@app/env'. 

       L4:  import { Response } from '@angular/http';
       L5:  import { ENV } from '@app/env';

[13:12:15]  typescript: src/services/customers/customers-service.ts, line: 6 
            Cannot find module '@app/env'. 

       L5:  import { Customer } from '../../models/customer';
       L6:  import { ENV } from '@app/env';

Error: Failed to transpile program
    at new BuildError (/Users/swaskey/Sites/dev/dashboard.com/node_modules/@ionic/app-scripts/dist/util/errors.js:16:28)
    at /Users/swaskey/Sites/dev/dashboard.com/node_modules/@ionic/app-scripts/dist/transpile.js:159:20
    at new Promise (<anonymous>)
    at transpileWorker (/Users/swaskey/Sites/dev/dashboard.com/node_modules/@ionic/app-scripts/dist/transpile.js:107:12)
    at Object.transpile (/Users/swaskey/Sites/dev/dashboard.com/node_modules/@ionic/app-scripts/dist/transpile.js:64:12)
    at /Users/swaskey/Sites/dev/dashboard.com/node_modules/@ionic/app-scripts/dist/build.js:109:82
    at <anonymous>

Attempted: Two different path settings.

...
  "baseUrl": "./src",
  "paths": {
    "@app/env": [
      "environments/environment"
    ]
  }


...
  "baseUrl": "./src",
  "paths": {
    "@app/env": [
      "config"
    ]
  }

Ionic Info

cli packages: (/Users/swaskey/.npm-global/lib/node_modules)

    @ionic/cli-utils  : 1.19.1
    ionic (Ionic CLI) : 3.19.1

global packages:

    cordova (Cordova CLI) : 8.0.0 

local packages:

    @ionic/app-scripts : 3.1.6
    Cordova Platforms  : browser 5.0.3 ios 4.5.4
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node  : v8.9.3
    npm   : 5.5.1 
    OS    : macOS High Sierra
    Xcode : Xcode 9.2 Build version 9C40b 

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

stevenwaskey avatar Feb 06 '18 18:02 stevenwaskey

Any news or update on this issue?

jbagaresgaray avatar Mar 08 '18 01:03 jbagaresgaray

Hey @jbagaresgaray @stevenwaskey , I have integrated on DEV/PROD, Now It is works correctly! I think that You will need to update ionic cli and this plugin. Then reinstall platform iOS/Android.

If you have same problem, I will share a project about this later.

wilfredonoyola avatar Mar 08 '18 17:03 wilfredonoyola

Unfortunately, we ended up going another route because we were unable to determine & resolve the root cause of the issue. With that said, I'd prefer us to use this plugin.

It appears that Ionic-cli is currently at 3.19.1. And this repo hasn't received an update for at least 3 months. Unless I'm overlooking something, we should have already been using all the latest packages.

stevenwaskey avatar Mar 08 '18 18:03 stevenwaskey

I'm not sure why this happens to you, I integrated this last week and the first time I tried this, this worked correctly. However, I will hope that this plugin receive an update.

wilfredonoyola avatar Mar 08 '18 18:03 wilfredonoyola

In your tsconfig.json, make sure that the path that @app/env resolves to actually exists. E.g. with my example below, ensure that you have a file src/environments/environment.DEV.ts. Before I added the "DEV" in my tsconfig.json, I was getting the same Cannot find module '@app/env'. error.

    "baseUrl": "./src",
    "paths": {
      "@app/env": [
        "environments/environment.DEV"
      ]
    }

AndrWeisR avatar Mar 29 '18 06:03 AndrWeisR

I have the same problem, when run ionic cordova build ios --prod

Module not found: Error: Can't resolve '@app/env' in '/src/pages/home'

cesarin3134 avatar May 08 '18 16:05 cesarin3134

Same issue here... :( Any clue .. ?

SipGit avatar Jun 14 '18 09:06 SipGit

I've just added every run script I wanted in the package.json, such as: "staging": "set MY_ENV=staging&& ionic-app-scripts serve", (Windows) "lab:prod": "set MY_ENV=prod&& ionic lab" (Windows)

"staging": "export MY_ENV=staging&& ionic-app-scripts serve", (MacOS) "lab:prod": "export MY_ENV=prod&& ionic lab" (MacOS)

and running: npm run {{ name_of_the_script }} solved the problem

borjalo avatar Jun 14 '18 14:06 borjalo