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. Understanding expressjs middleware with a visual example
  2. Disable eslint no-unused-vars warning on global functions
  3. Configuring jshint as a pre-commit hook for your nodejs applications
  4. Use node in es6 syntax with babel transpiling
  5. What does npm start do in nodejs
  6. Find the environment variables of a nodejs process in linux
  7. Scaling a basic nodejs application using clusters
  8. Configure The 'script' tag In package.json To Run Multiple Commands