2
votes

I've updated my ionic app from beta 11 to rc0. So it means I've switched from angular2 rc4 to angular2 stable, from typescript 1.8 to 2 and using the rollupjs module bundler.

I have a redux architecture and am using the Redux library.

I'm not able to compile and getting this error:

Error: Module c:\XXX\node_modules\redux\node_modules\symbol-observable\index.js does not export default (imported by c:\XXX\node_modules\redux\es\createStore.js)

at Module.trace (c:\XXX\node_modules\rollup\dist\rollup.js:7677:29)

at ModuleScope.findDeclaration (c:\XXX\node_modules\rollup\dist\rollup.js:7300:22)

at Scope.findDeclaration (c:\XXX\node_modules\rollup\dist\rollup.js:5351:39)

at Scope.findDeclaration (c:\XXX\node_modules\rollup\dist\rollup.js:5351:39)

at Identifier.bind (c:\XXX\node_modules\rollup\dist\rollup.js:6489:29)

at c:\XXX\node_modules\rollup\dist\rollup.js:5151:50

at MemberExpression.eachChild (c:\XXX\node_modules\rollup\dist\rollup.js:5168:5)

at MemberExpression.bind (c:\XXX\node_modules\rollup\dist\rollup.js:5151:7)

at MemberExpression.bind (c:\XXX\node_modules\rollup\dist\rollup.js:6693:24)

at c:\XXX\node_modules\rollup\dist\rollup.js:5151:50

Anyone has any ideas on what's going on? Can someone give me some pointers? I don't really understand on how to deal with this.

This is what I have in the rollup.config.js

var ngTemplate = require('../dist/plugins/ng-template').ngTemplate;
var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');

// https://github.com/rollup/rollup/wiki/JavaScript-API

module.exports = {
  /**
   * entry: The bundle's starting point. This file will
   * be included, along with the minimum necessary code
   * from its dependencies
   */
  entry: './.tmp/app/main.dev.js',

  /**
   * sourceMap: If true, a separate sourcemap file will
   * be created.
   */
  sourceMap: true,

  /**
   * format: The format of the generated bundle
   */
  format: 'iife',

  /**
   * dest: the output filename for the bundle in the buildDir
   */
  dest: 'main.js',

  // Add this to avoid Eval errors
  useStrict: false,

  /**
   * plugins: Array of plugin objects, or a single plugin object.
   * See https://github.com/rollup/rollup/wiki/Plugins for more info.
   */
  plugins: [
    ngTemplate(),
    commonjs({
        include: [
        'node_modules/rxjs/**',
        'node_modules/firebase/**',
        'node_modules/angularfire2/**'
        ],
        namedExports: {
        'node_modules/firebase/firebase.js': ['initializeApp', 'auth', 'database'],
        'node_modules/angularfire2/node_modules/firebase/firebase-browser.js': ['initializeApp', 'auth', 'database']
        }
    }),
    nodeResolve({
      module: true,
      jsnext: true,
      main: true,
      browser: true,
      extensions: ['.js']
    })
  ]

};
1

1 Answers

3
votes

The first part of the error...

Error: Module c:\XXX\node_modules\redux\node_modules\symbol-observable\index.js does not export default

...indicates that symbol-observable\index.js doesn't have an export default statement. That's because it's a CommonJS module – its entire contents are as follows:

module.exports = require('./lib/index');

So you'll need to convert that from CommonJS to ES. You already have rollup-plugin-commonjs set up, so hopefully it's just a case of reconfiguring it. Right now, only modules inside rxjs, firebase and angularfire2 are being converted.

Typically it's best to just include all of node_modules, because then you don't have to manually include dependencies-of-dependencies like symbol-observable:

plugins: [
ngTemplate(),
commonjs({
  include: [
    'node_modules/**'
  ],
  namedExports: {
    'node_modules/firebase/firebase.js': ['initializeApp', 'auth', 'database'],
    'node_modules/angularfire2/node_modules/firebase/firebase-browser.js': ['initializeApp', 'auth', 'database']
  }
}),
nodeResolve(...)

Any files inside node_modules that aren't CommonJS will just pass through the plugin unchanged.