Answer the question
In order to leave comments, you need to log in
How to include a function in nodeJS that is exported in a module as export default ()=>{}?
Folks, this is a problem.
There is a modul.js module written in es6 (inside imports and all things), which throws out the function
export default () => {}
This module is processed by webpac'om (babel-loader)
I get module_after_babel.js
Next, in nodeJS, I try to acquire this module to get its function
const fn = require('./module_after_babel.js');
Error that fn is not a function.
Answer the question
In order to leave comments, you need to log in
I 'll add to RidgeA
's answer
in the webpack config add:
{
output: {
filename: 'out_file.js',
path: 'out/path',
library: 'тут что угодно',
libraryTarget: 'commonjs2'
},
target: 'node' //чтоб нативные модули ноды не полифилил
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question