Problem updating react-dev-utils to support webpack4
See original GitHub issueIs this a bug report?
Yes, or I think so
Did you try recovering your dependencies?
Yes, I tried with a blank project
Which terms did you search for in User Guide?
N/A
Description
Hi, I ejected my project from create-react-app a time ago and now I’m modifying the code to support webpack 4 and I saw you already updated create-react-app and react-dev-utils to support it, so I updated react-dev-utils dependency to the latest version (5.0.1 at this time) but I just get the old webpack3 code in InterpolateHtmlPlugin.js instead of the one that is in this repo
...
"react-dev-utils": "5.0.1",
...
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// This Webpack plugin lets us interpolate custom variables into `index.html`.
// Usage: `new InterpolateHtmlPlugin({ 'MY_VARIABLE': 42 })`
// Then, you can use %MY_VARIABLE% in your `index.html`.
// It works in tandem with HtmlWebpackPlugin.
// Learn more about creating plugins like this:
// https://github.com/ampedandwired/html-webpack-plugin#events
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
class InterpolateHtmlPlugin {
constructor(replacements) {
this.replacements = replacements;
}
apply(compiler) {
compiler.plugin('compilation', compilation => {
compilation.plugin(
'html-webpack-plugin-before-html-processing',
(data, callback) => {
// Run HTML through a series of user-specified string replacements.
Object.keys(this.replacements).forEach(key => {
const value = this.replacements[key];
data.html = data.html.replace(
new RegExp('%' + escapeStringRegexp(key) + '%', 'g'),
value
);
});
callback(null, data);
}
);
});
}
}
module.exports = InterpolateHtmlPlugin;
When I am expecting this code
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// This Webpack plugin lets us interpolate custom variables into `index.html`.
// Usage: `new InterpolateHtmlPlugin({ 'MY_VARIABLE': 42 })`
// Then, you can use %MY_VARIABLE% in your `index.html`.
// It works in tandem with HtmlWebpackPlugin.
// Learn more about creating plugins like this:
// https://github.com/ampedandwired/html-webpack-plugin#events
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
class InterpolateHtmlPlugin {
constructor(replacements) {
this.replacements = replacements;
}
apply(compiler) {
compiler.hooks.compilation.tap('InterpolateHtmlPlugin', compilation => {
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tap(
'InterpolateHtmlPlugin',
data => {
// Run HTML through a series of user-specified string replacements.
Object.keys(this.replacements).forEach(key => {
const value = this.replacements[key];
data.html = data.html.replace(
new RegExp('%' + escapeStringRegexp(key) + '%', 'g'),
value
);
});
}
);
});
}
}
module.exports = InterpolateHtmlPlugin;
Maybe the npm package was not correctly updated? Or maybe I am doing something wrong?
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
When I update react-dev-utils to the @next version. I can't find ...
config.js file which is working with webpack4 . How can I fix this or do I need these two utils in my typescript...
Read more >How to Upgrade to React 17 and Webpack 5 Step by Step
1. Delete package-lock.json (not package. · 2. Delete node_modules in your project folder. · 3. Remove "babel-eslint" (or whatever the error ...
Read more >react-dev-utils - npm
webpack utilities used by Create React App. Latest version: 12.0.1, ... Start using react-dev-utils in your project by running `npm i ...
Read more >react-dev-utils | Yarn - Package Manager
Creates a webpack compiler instance for WebpackDevServer with built-in helpful messages. The args object accepts a number of properties: appName string : The ......
Read more >To v5 from v4 - webpack
Upgrade webpack 4 and its plugins/loaders · Make sure your build has no errors or warnings · Make sure to use mode ·...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe I was able to get past this issue.
Replace
var InterpolateHtmlPlugin = require('react-dev-utils/interpolate-html-plugin');
withvar InterpolateHtmlPlugin = require('interpolate-html-plugin');
.Make sure the
InterpolateHtmlPlugin
appears afterHtmlWebpackPlugin
in the plugin list.Now on to the next issue…
Thank you for your answer @iansu, can we release a new version of react-dev-utils for this?
I think this change worth a release because people like me who are looking to support webpack 4 have problems with this dependency at the moment