qpid-dispatch icon indicating copy to clipboard operation
qpid-dispatch copied to clipboard

DISPATCH-2339: Update react-scripts to 5; add CRACO to reapply polyfills

Open jiridanek opened this issue 2 years ago • 5 comments

Rhea ships with its sources in lib/ as well as single file in dist/. Using the lib/ sources with react-scripts 5 fails

$ npx react-scripts start
(node:836641) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:836641) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
Starting the development server...
Failed to compile.

Module not found: Error: Can't resolve 'os' in '/home/jdanek/repos/qpid/qpid-dispatch/console/react/node_modules/rhea/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
        - install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "os": false }
ERROR in ./node_modules/rhea/lib/connection.js 36:9-22
Module not found: Error: Can't resolve 'os' in '/home/jdanek/repos/qpid/qpid-dispatch/console/react/node_modules/rhea/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
        - install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "os": false }

ERROR in ./node_modules/rhea/lib/connection.js 38:11-26
Module not found: Error: Can't resolve 'path' in '/home/jdanek/repos/qpid/qpid-dispatch/console/react/node_modules/rhea/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

webpack compiled with 2 errors

The problem is that while rhea offers browserified bundled dist/rhea.js file already, but I could not figure out how to import it from the console's connection.js so that it passes through babel/webpack/whatever and it's exports are still visible.

"How do I browserify a file and then include it to be subsequently webpacked?"

I gave up on this and instead configured webpack to do the browserification the same way as it was with react-scripts 4.

jiridanek avatar Apr 21 '22 05:04 jiridanek

CC @bartoval Did you deal with this problem already?

jiridanek avatar Apr 21 '22 05:04 jiridanek

I wanted to wait for rhea release that would incorporate valerio's fix that makes CRACO (or other such workaround) unnecessary. But maybe best not to wait.

jiridanek avatar Jun 16 '22 13:06 jiridanek

I wanted to wait for rhea release that would incorporate valerio's fix that makes CRACO (or other such workaround) unnecessary. But maybe best not to wait.

IMO, we can wait. This update is not really urgent. Maybe we can ask if the rhea team plans to release the last updates.

bartoval avatar Jun 16 '22 16:06 bartoval

@jiridanek I see that the rhea library is updated to the version 3.0.1. We can remove this modification and add import rhea from "rhea/dist/rhea-umd"; in the connection.js file.

Let me know if you want to update the code here or in case i can create a new PR

bartoval avatar Nov 16 '22 22:11 bartoval

I looked into this some time ago. I had issues connecting the console to the router, which persisted regardless of versions of console and router that I used. Even older version that worked just fine in the past was unable to connect... I did not investigate in a greater detail then.

Currently I am on a sick leave, expected to last at least two or three weeks. I don't expect to find the time to look into this again this year.

jiridanek avatar Nov 17 '22 10:11 jiridanek