React is undefined in the .js compiled by npm

Viewed 24

I've always found some answers for every problem I got until now, and this is driving me crazy:

I'm working on a project divided in two sub-projects: one of these is the sidebar which is recalled by the main project, the "body". Both use React as library and Babel, but the sidebar use RollupJs as bundler, meanwhile the other use Webpack.

At the moment I have a problem in the sidebar: when compiling (I'm using NPM) the file is created as "sidebar.umd.min.js" in the dist directory, the browser console show me this error and the sidebar doesnt show up:

"Uncaught TypeError: Cannot use 'in' operator to search for 'default' in undefined",

Referred to this line

"var React__default = 'default' in React ? React['default'] : React;".

Like React is not loaded correctly. Terminal doesn't come up with any error during the compilation.

there is a screenshot

My first thought was that the React version (recently updated to 18) was the problem, but even after bringing it back to 16.14, the problem remained.

Do you ever got this problem? Or know where I can try to find some clues? I'm not even sure what I can post there to help you, cause in my mind the problem is too generic.

Thanks everyone for your attention, hoping for some help!

0 Answers
Related