How to include commonjs module in ES6 module node app?

Working with CommonJS modules is pretty straight forward.
You can only do default exports from CommonJS modules.

import packageMain from 'commonjs-package'; // Works
import { method } from 'commonjs-package'; // Errors

This means that all commonjs exports will live on the packageMain object, and you need to dot in to the packageMain object to pickup what you need.

packageMain.method1()

More info in the official nodejs docs

Leave a Comment