Ionic2 show 'System is not defined' after config rollup.config.js

166 views Asked by At

I added config in my package.json, and the rollup.config.js is below:

const rollupConfig = require('@ionic/app-scripts/config/rollup.config');
enter code hereconst replace = require('rollup-plugin-replace');

const isProd = (process.env.IONIC_ENV === 'prod');

console.log('cur ENV: ', process.env.IONIC_ENV);
const EnvConfig = {
  prod: {
    API_URL: ''
  },
  dev: {
    API_URL: 'http://localhost:3000'
  },
  deviceDev: {
    API_URL: 'http://192.168.1.7:3000'
  }
}

const curConfig = EnvConfig[process.env.IONIC_ENV]

const rollupConfigReplaceEnviroment = replace({
  exclude: 'node_modules/**',
  delimiters: ['<@', '@>'],
  // use the /environments/environment.dev as the default import(!), no stub needed.
  // note we only replace the "last" part of the import statement so relative paths are maintained
  'API_URL': curConfig.API_URL,
});

rollupConfig.plugins = rollupConfig.plugins || [];
rollupConfig.plugins.splice(0, 0, rollupConfigReplaceEnviroment);

module.exports = rollupConfig;

But when i run ionic serve -b, there is an warns show up: ```

[22:54:11]  rollup: commonjs-proxy:/Applications/My-Project/sharemap/node_modules/@angular/http/@angular/http.es5.js
            has issued a warning: 'default' is not exported by 'node_modules/@angular/http/@angular/http.es5.js'
[22:54:11]  rollup: commonjs-proxy:/Applications/My-Project/sharemap/node_modules/@angular/core/@angular/core.es5.js
            has issued a warning: 'default' is not exported by 'node_modules/@angular/core/@angular/core.es5.js'

then i run my app in browser, it show the error:

ERROR ReferenceError: System is not defined
    at loadAndCompile (main.js:82094)
    at NgModuleLoader.load (main.js:82071)
    at ModuleLoader.load (main.js:82147)
    at DeepLinker.getNavLinkComponent (main.js:56968)
    at DeepLinker.initViews (main.js:57039)
    at Nav.ngAfterViewInit (main.js:80489)
    at callProviderLifecycles (main.js:13220)
    at callElementProvidersLifecycles (main.js:13195)
    at callLifecycleHooksChildrenFirst (main.js:13179)
    at checkAndUpdateView (main.js:14211)

i think these maybe a bug for [email protected], and then i upgrade these lib to 8.2.0, but the problem still go on.

MY @ionic/app-scripts version is 2.1.4

My ionic info:

cli packages: (/Applications/My-Project/sharemap/node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : not installed

local packages:

    @ionic/app-scripts : 2.1.4
    Cordova Platforms  : none
    Ionic Framework    : ionic-angular 3.6.0

System:

    Android SDK Tools : 26.0.2
    ios-deploy        : 1.9.1
    ios-sim           : 6.0.0
    Node              : v8.4.0
    npm               : 5.2.0
    OS                : macOS Sierra
    Xcode             : Xcode 8.3.3 Build version 8E3004b
1

There are 1 answers

0
Dr. X On

You have to add package.json with a specific path as given below;

"config": {
        "ionic_copy": "./config/rollup.config.js"
    },

and rollup.config.js file will be in the config directory under the root directory with like projectName/config/rollup.config.js