export default returns undefined

Bug report

What is the current behavior?

index.js

import two from './two';

console.log('index');
console.log(two);

function foo () {
  return 'index foo'
}

export default foo;

two.js

import three from './three';

console.log('two');
console.log(three)

let bar = function foo () {
  return 'two foo'
}

export default bar;

three.js

import index from './index';

console.log('three');
console.log(index)

let bar = function foo () {
  return 'three foo'
}

export default bar;

config

module.exports = {
  entry: './index.js',
  output: {
    filename: 'index.js',
    path: path.resolve(__dirname, 'dist')
  }
};

when bundle and run in three.js index is not getting resolved, returns undefined

running the output file,

undefined
two
[Function]
index
[Function]

but instead if i do a direct export in index.js (export function foo), its working fine!

If the current behavior is a bug, please provide the steps to reproduce.
just run the above the code with the given config.

What is the expected behavior?
In an idle world it should resolve, or is it a normal behavior if so please explain why this happening! that will be super helpful.

Other relevant information:
webpack version: 4.16.1
Node.js version: v6.0.0
Operating System: MacOS High Sierra 10.13.5
Additional tools:

Author: Fantashit

1 thought on “export default returns undefined

  1. @sokra thanks for the help 🙂

    function foo () {
      return 'index foo'
    }
    
    export default foo;
    
    export default function foo () {
      return 'index foo'
    }
    

    but why these two examples are different? in both the cases I’m referering to the same method right? (but in the latter case it seems to be working fine and in the first one its not)

Comments are closed.