-1

I have some js code that wants to be imported using ES6 import syntax

import crazymodule from 'crazymodule';

How do I convert this to nodejs require syntax?

I've tried:

const crazymodule = require('crazymodule')
Ryan
  • 155
  • 1
  • 5
  • Possible duplicate of [Javascript require vs require .default](https://stackoverflow.com/questions/43247696/javascript-require-vs-require-default) – jmargolisvt Sep 09 '19 at 15:34

1 Answers1

0

I'd been googling for the answer for this for a while and didn't hit a good answer so I made this one to help future peeps using the same search terms as me.

That answer is you need to have .default on the end of the require line:

const crazymodule = require('crazymodule').default
Ryan
  • 155
  • 1
  • 5