1

I'm trying to run a plugin that throws me the exception require(...).default is not a function. The bin file is pretty simple:

'use strict';

require = require('esm')(module /*, options*/);
console.log('BANGBANG')
require('../src/main.js')
  .default()
  .parse(process.argv.slice(2));

My file.js is pretty simple:

export default main;

function main(cwd) {
  awesome code
}

What is wrong on my export default?

edit:

It works if i switch to:

'use strict';

require = require('esm')(module /*, options*/);
console.log('BANGBANG')
require('../src/main.js')()
  .parse(process.argv.slice(2));

Not sure if it's the "right" way.

NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • look at the main.js that is required. Does it export a default function? – Tom M Jan 31 '19 at 17:28
  • 1
    `default` is a keyword. To call your function, use `require('../src/main.js')(param)`. See here: https://stackoverflow.com/a/21117231/5734311 –  Jan 31 '19 at 17:30
  • Please tell us what module system you are using. There seems to be a difference how this is implemented between different environments (and even different version of the same environment) like nodejs, reactjs, etc – NineBerry Jan 31 '19 at 17:50
  • @NineBerry I'm using Node 8.10 and NPM 6.4.1 –  Jan 31 '19 at 17:54
  • 1
    You are using "esm" as a module manager while Nodejs actually already comes with its own module manager and additionally supports native JavaScript modules. Why do you mix that stuff? – NineBerry Jan 31 '19 at 18:12
  • Not sure! It's a dependency on internet - they use it to build react components (something like plugins). I'm trying to fix it because I really need to use it. –  Jan 31 '19 at 18:14
  • Are there special requirements like for example should the modules be used both on the server (in nodejs) and in the browser? – NineBerry Jan 31 '19 at 19:01

0 Answers0