Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack 5 Upgrade #22267

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"through2": "^3.0.1",
"tmp": "^0.1.0",
"typescript": "^3.7.5",
"webpack": "^4.41.2",
"webpack": "^5",
"yargs": "^15.3.1"
},
"devEngines": {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-devtools-core/webpack.backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module.exports = {
libraryTarget: 'umd',
},
resolve: {
fallback: {
fs: false,
ScriptedAlchemy marked this conversation as resolved.
Show resolved Hide resolved
},
alias: {
react: resolve(builtModulesDir, 'react'),
'react-debug-tools': resolve(builtModulesDir, 'react-debug-tools'),
Expand All @@ -55,9 +58,6 @@ module.exports = {
scheduler: resolve(builtModulesDir, 'scheduler'),
},
},
node: {
fs: 'empty',
},
plugins: [
new DefinePlugin({
__DEV__,
Expand Down
4 changes: 3 additions & 1 deletion packages/react-devtools-core/webpack.standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ module.exports = {
scheduler: resolve(builtModulesDir, 'scheduler'),
},
},
// webpack doesnt like these bundled
externals: ['utf-8-validate', 'bufferutil'],
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
node: {
// Don't replace __dirname!
// This would break the standalone DevTools ability to load the backend.
Expand Down Expand Up @@ -90,7 +92,7 @@ module.exports = {
test: /\.worker\.js$/,
use: [
{
loader: 'workerize-loader',
loader: 'workerize-loader-5',
options: {
inline: true,
},
Expand Down
8 changes: 4 additions & 4 deletions packages/react-devtools-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
"source-map-js": "^0.6.2",
"sourcemap-codec": "^1.4.8",
"style-loader": "^0.23.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3",
"workerize-loader": "^1.3.0"
"webpack": "^5",
"webpack-cli": "^4",
"webpack-dev-server": "^4",
"workerize-loader-5": "^1.4.0"
Copy link
Contributor

@bvaughn bvaughn Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something about this change causes the following error to be thrown in the extension process:

Uncaught ReferenceError: process is not defined

Looking at the code in question, I see:

(0, _utils.default)("ArrayExpression", {
  fields: {
    elements: {
      validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeOrValueType)("null", "Expression", "SpreadElement"))),
      default: !process.env.BABEL_TYPES_8_BREAKING ? [] : undefined
    }
  },
  visitor: ["elements"],
  aliases: ["Expression"]
});

Seems like this is coming from an imported module?

Seems like the result of this error is that the named hooks feature does not work. (Clicking the little "🪄" button for an inspected element eventually times out whereas it used to work.)


To reproduce this problem, build the extension as described here and then open a website like Code Sandbox and try to inspect a component with hooks. (You can see the error thrown when the extension is initializing actually, by undocking the DevTools and opening a second level of DevTools to inspect the extension.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will look into this further

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇🏼‍♂️ Thanks!

},
"dependencies": {
"web-ext": "^4"
Expand Down
8 changes: 0 additions & 8 deletions packages/react-devtools-extensions/webpack.backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ module.exports = {
path: __dirname + '/build',
filename: 'react_devtools_backend.js',
},
node: {
// Don't define a polyfill on window.setImmediate
setImmediate: false,

// source-maps package has a dependency on 'fs'
// but this build won't trigger that code path
fs: 'empty',
},
resolve: {
alias: {
react: resolve(builtModulesDir, 'react'),
Expand Down
10 changes: 1 addition & 9 deletions packages/react-devtools-extensions/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ module.exports = {
publicPath: '/build/',
filename: '[name].js',
},
node: {
// Don't define a polyfill on window.setImmediate
setImmediate: false,

// source-maps package has a dependency on 'fs'
// but this build won't trigger that code path
fs: 'empty',
},
resolve: {
alias: {
react: resolve(builtModulesDir, 'react'),
Expand Down Expand Up @@ -110,7 +102,7 @@ module.exports = {
test: /\.worker\.js$/,
use: [
{
loader: 'workerize-loader',
loader: 'workerize-loader-5',
options: {
inline: true,
},
Expand Down
8 changes: 4 additions & 4 deletions packages/react-devtools-inline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"file-loader": "^6.1.0",
"raw-loader": "^3.1.0",
"style-loader": "^0.23.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3",
"worker-loader": "^3.0.3"
"webpack": "^5",
"webpack-cli": "^4",
"webpack-dev-server": "^4",
"worker-loader": "^3.0.8"
}
}
10 changes: 4 additions & 6 deletions packages/react-devtools-inline/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ module.exports = {
'react-is': 'react-is',
scheduler: 'scheduler',
},
node: {
// source-maps package has a dependency on 'fs'
// but this build won't trigger that code path
fs: 'empty',
},
resolve: {
alias: {
'react-devtools-feature-flags': resolveFeatureFlags('inline'),
Expand Down Expand Up @@ -84,13 +79,16 @@ module.exports = {
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"${LIGHT_MODE_DIMMED_LOG_COLOR}"`,
}),
],
stats: {
children: true,
},
module: {
rules: [
{
test: /\.worker\.js$/,
use: [
{
loader: 'workerize-loader',
loader: 'workerize-loader-5',
options: {
inline: true,
},
Expand Down
8 changes: 4 additions & 4 deletions packages/react-devtools-scheduling-profiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"babel-loader": "^8.1.0",
"css-loader": "^4.2.1",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^4.3.0",
"html-webpack-plugin": "^5",
"style-loader": "^1.2.1",
"url-loader": "^4.1.0",
"vercel": "^20.1.0",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0",
"webpack": "^5",
"webpack-cli": "^4",
"webpack-dev-server": "^4",
"worker-loader": "^3.0.2"
}
}
7 changes: 4 additions & 3 deletions packages/react-devtools-shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
"babel-loader": "^8.0.4",
"cross-env": "^3.1.4",
"css-loader": "^1.0.1",
"html-webpack-plugin": "^5",
"raw-loader": "^3.1.0",
"style-loader": "^0.23.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
"webpack": "^5",
"webpack-cli": "^4",
"webpack-dev-server": "^4"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The react-devtools-shell test app is broken by this change. (I think actually it's the react-devtools-inline package that gets broken, but I'll explain that below.)

Looks like the page is trying to request /dist/devtools.js and it's getting a 400 response. (Interestingly, the page is also requesting /devtools.js and that's returning okay.)

Editing the index.html file so the <script> tag loads /devtools.js instead (no /dist/...) fixes the failed network requests, but still doesn't fix the broken shell.

I see the following error in the console:

Uncaught TypeError: (0 , react_devtools_inline_backend__WEBPACK_IMPORTED_MODULE_2__.initialize) is not a function

I also see a few (related?) warnings in the console when running the test shell:

WARNING in ./src/devtools.js 14:0-17
export 'initialize' (imported as 'initializeBackend') was not found in 'react-devtools-inline/backend' (possible exports: backend)

WARNING in ./src/devtools.js 17:17-35
export 'initialize' (imported as 'initializeFrontend') was not found in 'react-devtools-inline/frontend' (possible exports: frontend)

WARNING in ./src/devtools.js 20:0-15
export 'activate' (imported as 'activateBackend') was not found in 'react-devtools-inline/backend' (possible exports: backend)

Inspecting the imported module, it looks like there's an extra backend wrapper now, e.g.

// module:
{
  backend: {
    activate: (...),
    initialize: (...)
  }
}

Whereas before it was:

// module:
{
  activate: (...),
  initialize: (...)
}

This behavior can be reproduced by following the steps here:
https://github.com/facebook/react/blob/main/packages/react-devtools/CONTRIBUTING.md#option-1-fastest-using-the-test-shell

Then loading localhost:8080.

Copy link
Contributor

@bvaughn bvaughn Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could work around this by updating the entrypoint files like so:

react-devtools-inline/backend.js

module.exports = require('./dist/backend').backend;

react-devtools-inline/frontend.js

module.exports = require('./dist/frontend').frontend;

But I don't know why this is necessary or (more importantly) what other places it might cause trouble.

Anyway, in the spirit of testing, I've made this change locally to see if things works otherwise– and it looks like the DevTools UI is not visible in the test shell (so something is still broken) and I see the following two errors in the console:

GET http://localhost:8080/dist/devtools.js net::ERR_ABORTED 404 (Not Found)

GET http://localhost:8080/dist/app.js net::ERR_ABORTED 404 (Not Found)

Here's my local changes when testing this (in case it helps you any):

diff --git a/packages/react-devtools-inline/backend.js b/packages/react-devtools-inline/backend.js
index 2c2a32d45..dbfbf7b34 100644
--- a/packages/react-devtools-inline/backend.js
+++ b/packages/react-devtools-inline/backend.js
@@ -1 +1 @@
-module.exports = require('./dist/backend');
+module.exports = require('./dist/backend').backend;
diff --git a/packages/react-devtools-inline/frontend.js b/packages/react-devtools-inline/frontend.js
index a86be2237..4700af89e 100644
--- a/packages/react-devtools-inline/frontend.js
+++ b/packages/react-devtools-inline/frontend.js
@@ -1 +1 @@
-module.exports = require('./dist/frontend');
+module.exports = require('./dist/frontend').frontend;
\ No newline at end of file
diff --git a/packages/react-devtools-shell/src/app/index.js b/packages/react-devtools-shell/src/app/index.js
index 805cd0a2a..4278daaf0 100644
--- a/packages/react-devtools-shell/src/app/index.js
+++ b/packages/react-devtools-shell/src/app/index.js
@@ -12,7 +12,7 @@ import Iframe from './Iframe';
 import EditableProps from './EditableProps';
 import ElementTypes from './ElementTypes';
 import Hydration from './Hydration';
-import InlineWarnings from './InlineWarnings';
+// import InlineWarnings from './InlineWarnings';
 import InspectableElements from './InspectableElements';
 import ReactNativeWeb from './ReactNativeWeb';
 import ToDoList from './ToDoList';
@@ -53,7 +53,7 @@ function mountTestApp() {
   mountHelper(Hydration);
   mountHelper(ElementTypes);
   mountHelper(EditableProps);
-  mountHelper(InlineWarnings);
+  // mountHelper(InlineWarnings);
   mountHelper(ReactNativeWeb);
   mountHelper(Toggle);
   mountHelper(ErrorBoundaries);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I can fix the GET failures by modifying the following files:

diff --git a/packages/react-devtools-shell/index.html b/packages/react-devtools-shell/index.html
index 410dc5bdc..732ba5db6 100644
--- a/packages/react-devtools-shell/index.html
+++ b/packages/react-devtools-shell/index.html
@@ -64,6 +64,6 @@
     <!-- This script installs the hook, injects the backend, and renders the DevTools UI -->
     <!-- In DEV mode, this file is served by the Webpack dev server -->
     <!-- For production builds, it's built by Webpack and uploaded from the local file system -->
-    <script src="dist/devtools.js"></script>
+    <script src="devtools.js"></script>
   </body>
 </html>
\ No newline at end of file

diff --git a/packages/react-devtools-shell/src/devtools.js b/packages/react-devtools-shell/src/devtools.js
index fda4c91b7..c7fbd3a1c 100644
--- a/packages/react-devtools-shell/src/devtools.js
+++ b/packages/react-devtools-shell/src/devtools.js
@@ -50,7 +50,7 @@ mountButton.addEventListener('click', function() {
   }
 });
 
-inject('dist/app.js', () => {
+inject('app.js', () => {
   initDevTools({
     connect(cb) {
       const root = createRoot(container);

But now for some reason the test app code loads 3 times in the page (so there's 3 duplicate copies) and DevTools UI is still not visible at all (though it's loading). It looks like the CSS/styles are weird somehow, because the DevTools UI is loading in the background (behind the duplicate copies of the app).

Digging in a little more, I see a lot of <div> elements in the root of the page (outside of the <iframe> the test app is supposed to load into). Deleting them reveals the DevTools UI underneath, and it even mostly works, but there are a lot of "duplicate ID" errors in the console (presumably from the duplicate test apps) so...something wonky is still going on here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly related to the "3 copies of the app are on the page" thing I mentioned above– the console also shows 3 copies of these logs:

VM7176 devtools.js:17483         [HMR] Waiting for update signal from WDS...
VM7176 devtools.js:4692          Download the React DevTools for a better development experience: https://reactjs.org/link/react-devtools
log.js:24                        [HMR] Waiting for update signal from WDS...
react-dom.development.js:29044   Download the React DevTools for a better development experience: https://reactjs.org/link/react-devtools
console.js:29                    [HMR] Waiting for update signal from WDS...
react-dom.development.js:29044   Download the React DevTools for a better development experience: https://reactjs.org/link/react-devtools
VM7176 devtools.js:11398         [webpack-dev-server] Hot Module Replacement enabled.
index.js:519                     [webpack-dev-server] Hot Module Replacement enabled.
index.js:519                     [webpack-dev-server] Hot Module Replacement enabled.
VM7176 devtools.js:11398         [webpack-dev-server] Live Reloading enabled.
index.js:519                     [webpack-dev-server] Live Reloading enabled.
index.js:519                     [webpack-dev-server] Live Reloading enabled.

Spaces added by me to highlight the fact that– although the content of the logs is the same, the file locations are different. I think this suggests that Webpack is bundling things oddly?

37 changes: 28 additions & 9 deletions packages/react-devtools-shell/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {resolve} = require('path');
const {DefinePlugin} = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {
DARK_MODE_DIMMED_WARNING_COLOR,
DARK_MODE_DIMMED_ERROR_COLOR,
Expand Down Expand Up @@ -32,16 +33,11 @@ const DEVTOOLS_VERSION = getVersionString();

const config = {
mode: __DEV__ ? 'development' : 'production',
devtool: __DEV__ ? 'cheap-module-eval-source-map' : 'source-map',
devtool: __DEV__ ? 'cheap-module-source-map' : 'source-map',
entry: {
app: './src/app/index.js',
devtools: './src/devtools.js',
},
node: {
// source-maps package has a dependency on 'fs'
// but this build won't trigger that code path
fs: 'empty',
},
resolve: {
alias: {
react: resolve(builtModulesDir, 'react'),
Expand All @@ -56,6 +52,9 @@ const config = {
minimize: false,
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
}),
new DefinePlugin({
__DEV__,
__EXPERIMENTAL__: true,
Expand Down Expand Up @@ -111,9 +110,29 @@ if (TARGET === 'local') {
config.devServer = {
hot: true,
port: 8080,
clientLogLevel: 'warning',
publicPath: '/dist/',
stats: 'errors-only',
static: {
directory: resolve(__dirname, 'dist'),
},
client: {
overlay: {
errors: true,
warnings: false,
ScriptedAlchemy marked this conversation as resolved.
Show resolved Hide resolved
},
},
// historyApiFallback: {
// index: 'index.html'
// },
// proxy: {
// '/': {
// target: 'http://localhost:8080',
// bypass: function (request, response, proxyOptions) {
// if (request.url === '/') {
// console.log('FOUND IT')
// return '/index.html';
// }
// },
// },
// },
ScriptedAlchemy marked this conversation as resolved.
Show resolved Hide resolved
};
} else {
config.output = {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"peerDependencies": {
"react": "^17.0.0",
"react-dom": "^17.0.0",
"webpack": "^4.43.0"
"webpack": "^5"
Copy link
Contributor

@bvaughn bvaughn Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to downgrade this back to Webpack 4, e.g.

@sebmarkbage says this plug-in doesn’t work with Webpack 5 since it uses internals and plug-in apis and needs to be ported. (And there's currently no automated test coverage to verify this does or doesn't work.)

Edit 1 Apparently we can test this by building and then yarn starting the fixture in /fixtures/flight/.

The built bundle has a peer dependency on Webpack 4 (via the workspaces) and this might cause problems. I'll test this.

Edit 2: @sebmarkbage has also expressed concern that this change would break this demo: https://github.com/reactjs/server-components-demo


Can we rollback the peer dependency change for this package only?

Copy link
Contributor

@bvaughn bvaughn Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for revering the change to packages/react-server-dom-webpack/package.json peer dependencies.

I've tested the flight fixture after your most recent commit:

# root
yarn install
yarn build

# fixtures/flight
yarn install
yarn start

Loading localhost:3000 shows the following warnings/errors:

Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot

Failed to load resource: net::ERR_CONNECTION_REFUSED

Uncaught TypeError: Failed to fetch
  The above error occurred in the <Content> component:

    at Content
    at Suspense

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

The first warning is expected and indicates that the fixture is just a little out of date. The following errors seem bad though.

For comparison, I've tested the same steps on HEAD of main branch, and I see the app load successfully. So it seems like this update certainly breaks the flight fixture – but would presumably not break the downstream packages/dependencies.

cc @sebmarkbage to confirm is this is acceptable for the time being?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixture is acceptable but we need to fix the published package. Worst case maybe we can turn this to private: true and exclude it from future builds to avoid confusion until it's fixed.

Copy link
Contributor

@bvaughn bvaughn Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, we're commenting on an outdated version of this PR here. This change was reverted in 13f3bd6 and the latest commit state makes no changes to the packages/react-server-dom-webpack/package.json package (or its peer dependencies)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the drive-by.

says this plug-in doesn’t work with Webpack 5 since it uses internals and plug-in apis and needs to be ported. (And there's currently no automated test coverage to verify this does or doesn't work.)

I wrote a PR a while ago to support both webpack 5 and webpack 4 (https://github.com/facebook/react/pull/20524/files) in the react-dom-server-webpack plugin package.

If there is interest, I would be happy to pick it back up and get it into a state where it could be merged in? It sounds like we'd want to add automated tests for the plugin before merging the linked PR.

},
"dependencies": {
"acorn": "^6.2.1",
Expand Down
Loading