Be the first user to complete this post

  • 0
Add to List

exports is not defined

This is very common error when your project has ES6 modules as well as require.js module systems. Here, I will show you few examples on how to require ES6 modules inside an AMD module. It will help you mitigate such errors.

default export

// Employee.js

function Employee () {
 ...
}

export default new Employee();

// HR.js

var Employee = require('Employee').default;

named export

// Employee.js

function Employee () {
 ...
}

export const employee = new Employee();

// HR.js

var Employee = require('Employee').employee;

default is also a named export, with its name being default.





Also Read:

  1. Error handling in promises interview question
  2. Generating container components with connect utility in react redux app
  3. Accessing the request body and session in nodejs using express
  4. Unit test your Nodejs RESTful API using mocha
  5. Understanding nodejs module exports and require
  6. Creating a simple event emitter using nodejs
  7. Installing, Listing and Uninstalling packages using npm
  8. Redux: Implementing store from scratch