Hi!
I want run the same script both in nodejs and browser.
I use latest nodejs 13.9.0 which supports ECMAScript modules. And I use create-react-app to build application for browser.
import * as R from 'ramda'; works well in browser but in nodejs it is imported as { default: { ...R functions}}
import R from 'ramda'; works well in nodejs but in browser it returns error
Attempted import error: 'ramda' does not contain a default export (imported as 'R').
I'm not a fan of default imports so if it will work as import * as R from 'ramda'; everywhere it will be awesome.
Is it possible to do something about it? Maybe some solution or workaround?
UPD. I made a very straightforward hack but it is ugly.
import * as R2 from 'ramda';
let R;
// need to hide the "default" call from webpack.
// Otherwise it returns: 'ramda' does not contain a default export
function getter(obj, prop) {
return obj[prop];
}
if (Object.keys(R2).length === 1) {
R = getter(R2, 'default');
} else {
R = R2;
}
Hi!
I want run the same script both in nodejs and browser.
I use latest nodejs 13.9.0 which supports ECMAScript modules. And I use create-react-app to build application for browser.
import * as R from 'ramda';works well in browser but in nodejs it is imported as{ default: { ...R functions}}import R from 'ramda';works well in nodejs but in browser it returns errorAttempted import error: 'ramda' does not contain a default export (imported as 'R').I'm not a fan of default imports so if it will work as
import * as R from 'ramda';everywhere it will be awesome.Is it possible to do something about it? Maybe some solution or workaround?
UPD. I made a very straightforward hack but it is ugly.