ionic-team / ionic-app-scripts

App Build Scripts for Ionic Projects
http://ionicframework.com/
MIT License
609 stars 300 forks source link

custom webpack config not loaded using --prod #1137

Open luckylooke opened 6 years ago

luckylooke commented 6 years ago

Short description of the problem:

Hello, I am using package.json to define custom webpack config file via ionic_webpack and it is not called/loaded on building with --prod flag, as workaround I had to downgrade ionic-app-scripts to 1.2.5 to make it work again.

What behavior are you expecting?

custom webpack file to be callled/loaded Working aliases same way as they work without --prod flag.

Steps to reproduce:

  1. setup package.json

    "config": {
        "ionic_webpack": "./config/webpack-extension.config.js"
    },

    webpack-extension.config.js

    let useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js')
    module.exports = function () {
    
    console.log('process.env.IONIC_ENV: ', process.env.IONIC_ENV) // without using --prod, this log 'process.env.IONIC_ENV:dev' into console
    
    useDefaultConfig.resolve.alias = {
        "@app/env": path.resolve(__dirname + '/../src/environments/env.' + process.env.IONIC_ENV + '.ts'),
    };
    return useDefaultConfig;
    }

    environment.ts

    import {
    isDEV_,
    GET_HOST_,
    } from '@app/env'
  2. build with prod ionic cordova build android --device --prod

Which @ionic/app-scripts version are you using? tested with 2.0.1, 1.3.12, 1.3.7, 1.3.4 finnaly 1.2.5 did work well

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

console:

ionic cordova build android --device --prod

Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser

[08:14:24]  build prod started ... 
[08:14:24]  clean started ... 
[08:14:24]  clean finished in 2 ms 
[08:14:24]  copy started ... 
[08:14:24]  ngc started ... 
[08:14:48]  ngc finished in 24.13 s 
[08:14:48]  preprocess started ... 
[08:14:48]  deeplinks started ... 
[08:14:48]  deeplinks finished in 27 ms 
[08:14:48]  optimization started ... 
[08:14:57]  copy finished in 32.90 s 
[WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova). Your plugins may be out of
       date.
Error: ./src/environments/environment.js
Module not found: Error: Can't resolve '@app/env' in '/Users/myuser/myproject/client/src/environments'
resolve '@app/env' in '/Users/myuser/myproject/client/src/environments'
  Parsed request is a module
  using description file: /Users/myuser/myproject/client/package.json (relative path: ./src/environments)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /Users/myuser/myproject/client/package.json (relative path: ./src/environments)
    resolve as module
      /Users/myuser/myproject/client/src/environments/node_modules doesn't exist or is not a directory
      /Users/myuser/myproject/client/src/node_modules doesn't exist or is not a directory
      /Users/myuser/myproject/node_modules doesn't exist or is not a directory
      /Users/myuser/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /Users/myuser/myproject/client/node_modules
        using description file:/Users/myuser/myproject/client/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: /Users/myuser/myproject/client/package.json (relative path: ./node_modules)
          using description file: /Users/myuser/myproject/client/package.json (relative path: ./node_modules/@app/env)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/myuser/myproject/client/node_modules/@app/env doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/myuser/myproject/client/node_modules/@app/env.js doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Users/myuser/myproject/client/node_modules/@app/env.ts doesn't exist
            as directory
              /Users/myuser/myproject/client/node_modules/@app/env doesn't exist
[/Users/myuser/myproject/client/src/environments/node_modules]
[/Users/myuser/myproject/client/src/node_modules]
[/Users/myuser/myproject/node_modules]
[/Users/myuser/node_modules]
[/Users/node_modules]
[/node_modules]
[/Users/myuser/myproject/client/node_modules/@app/env]
[/Users/myuser/myproject/client/node_modules/@app/env.js]
[/Users/myuser/myproject/client/node_modules/@app/env.ts]
[/Users/myuser/myproject/client/node_modules/@app/env]
 @ ./src/environments/environment.js 1:0-62
 @ ./src/app/main.ts

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myproject@ build-android-prod: `node config/setMobileExports && ionic cordova build android --device --prod`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the myproject@ build-android-prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/myuser/.npm/_logs/2017-07-21T06_15_04_196Z-debug.log

additional info from debug.log

13 verbose stack Error: myproject@ build-android-prod: `node config/setMobileExports && ionic cordova build android --device --prod`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/Users/myuser/.npm-global/lib/node_modules/npm/lib/utils/lifecycle.js:289:16)
13 verbose stack     at emitTwo (events.js:106:13)
13 verbose stack     at EventEmitter.emit (events.js:191:7)
13 verbose stack     at ChildProcess.<anonymous> (/Users/myuser/.npm-global/lib/node_modules/npm/lib/utils/spawn.js:40:14)
13 verbose stack     at emitTwo (events.js:106:13)
13 verbose stack     at ChildProcess.emit (events.js:191:7)
13 verbose stack     at maybeClose (internal/child_process.js:877:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
14 verbose pkgid myproject@
15 verbose cwd /Users/myuser/myproject/client
16 verbose Darwin 16.6.0
17 verbose argv "/usr/local/bin/node" "/Users/myuser/.npm-global/bin/npm" "run" "build-android-prod"
18 verbose node v6.9.5
19 verbose npm  v5.3.0

Thank you

distante commented 6 years ago

Oh, I was looking to do this too (extend the paths in webpack). Since it does not work with --prod I suppose I should wait until it gets fixed.

kinglionsoft commented 6 years ago

I am having the same issue.

tgensol commented 6 years ago

Same here

tgensol commented 6 years ago

Any news on this one ? I am still having issue (with using phaser-ce)

renanmzmendes commented 6 years ago

+1

l0ne commented 6 years ago

+1

franbueno commented 6 years ago

+1

samuelbirk commented 6 years ago

+1