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 9 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
3 changes: 0 additions & 3 deletions packages/react-devtools-core/webpack.backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,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?

23 changes: 14 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,15 @@ 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: true,
},
},
};
} else {
config.output = {
Expand Down
Loading