node.js - Rollup Creating Undefined Variable -


i trying use grunt rollup plugin, grunt-rollup, compile 2 es6 files javascript can run node , browser. currently, compiles, rollup seems creating undefined variable 1 of class names. here current configuration.

imported es6 file (src/base.js):

class base{    constructor() {     return this;     } }  export default test; 

rollup entrypoint es6 file (src/test.js):

import base "./base";  class test extends base{    constructor() {     super();     return this;     } }  export default test; 

gruntfile.js

module.exports = function(grunt) {    var babel = require('rollup-plugin-babel');   var resolve = require('rollup-plugin-node-resolve');    // project configuration.   grunt.initconfig({     pkg: grunt.file.readjson('package.json'),      rollup: {       options: {         sourcemap: true,         format: 'cjs',         plugins: function () {           return [             resolve({               // pass custom options resolve plugin               customresolveoptions: {                 moduledirectory: 'node_modules'               }             }),             babel({               exclude: './node_modules/**',               presets: ['es2015-rollup']             }),           ];         },       },       main: {         dest: 'dest/bundle.js',         src: 'src/test.js'       }     },      uglify: {       main: {         options: {           sourcemap: true,           sourcemapname: 'dest/bundle.min.js.map'         },         files: {           'dest/bundle.min.js': ['dest/bundle.js']         }       }     }   });    grunt.loadnpmtasks('grunt-rollup');   grunt.loadnpmtasks('grunt-contrib-uglify');    // default task(s).   grunt.registertask('default', ['rollup', 'uglify']);  }; 

output file (dest/bundle.js)

'use strict';  var classcallcheck = function (instance, constructor) {   if (!(instance instanceof constructor)) {     throw new typeerror("cannot call class function");   } };    var inherits = function (subclass, superclass) {   if (typeof superclass !== "function" && superclass !== null) {     throw new typeerror("super expression must either null or function, not " + typeof superclass);   }    subclass.prototype = object.create(superclass && superclass.prototype, {     constructor: {       value: subclass,       enumerable: false,       writable: true,       configurable: true     }   });   if (superclass) object.setprototypeof ? object.setprototypeof(subclass, superclass) : subclass.__proto__ = superclass; };    var possibleconstructorreturn = function (self, call) {   if (!self) {     throw new referenceerror("this hasn't been initialised - super() hasn't been called");   }    return call && (typeof call === "object" || typeof call === "function") ? call : self; };  var test$1 = function (_base) {   inherits(test$$1, _base);    function test$$1() {     var _ret;      classcallcheck(this, test$$1);      var _this = possibleconstructorreturn(this, (test$$1.__proto__ || object.getprototypeof(test$$1)).call(this));      return _ret = _this, possibleconstructorreturn(_this, _ret);   }    return test$$1; }(test);  module.exports = test$1;  //# sourcemappingurl=bundle.js.map 

terminal output

output after running node dest/bundle.js.

/users/christianjuth/desktop/mb-problems/dest/bundle.js:67 }(test);   ^  referenceerror: test not defined     @ object.<anonymous> (/users/christianjuth/desktop/mb-problems/dest/bundle.js:67:3)     @ module._compile (module.js:569:30)     @ object.module._extensions..js (module.js:580:10)     @ module.load (module.js:503:32)     @ trymoduleload (module.js:466:12)     @ function.module._load (module.js:458:3)     @ function.module.runmain (module.js:605:10)     @ startup (bootstrap_node.js:158:16)     @ bootstrap_node.js:575:3 

the problem seems end of bundle.js }(test); looking undefined variable. far can tell not bug code. seems issue how rollup compiling es6.

that's because have undefined variable in code. take second @ base.js:

class base{    constructor() {     return this;     } }  export default test; 

...where have defined test? did mean export default base?


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -