Unable to override webpack configuration for a react application
See original GitHub issueSummary
I have bootstrapped a react application in my workspace
using:
nx generate @nrwl/react:application
I want to override the webpack.config.js
to add a few more plugins
I noticed that in the workspace.json
for my project there is already webpackConfig
option
"architect": {
"build": {
"builder": "@nrwl/web:build",
"options": {
"webpackConfig": "@nrwl/react/plugins/webpack",
I followed the instructions mentioned here (which may be for projects which use the @nrwl/node or @nrwl/web) and pointed it to a custom version of my webpack.config
which looks like this
const WebpackNotifierPlugin = require('webpack-notifier');
module.exports = (config, context) => {
console.log(config);
return {
...config,
plugins: [
...config.plugins,
new WebpackNotifierPlugin({title: 'Project build completed'}),
]
};
};
but I get the error when i try to build my project nx run frontend:build
:
ERROR in ./main.tsx 4:16
Module parse failed: Unexpected token (4:16)
File was processed with these loaders:
* ../../../node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| import ReactDOM from 'react-dom';
| import App from './app/app';
> ReactDOM.render(<App />, document.getElementById('root'));
Can I get some help with this? Is this the recommended way to override the webpack.config for a react based application?
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
I can't modify webpack.config in create-react-app to install ...
I put two scripts (start.js and build.js) in a scripts folder in root directory (i.e. outside src). Then in package.json change the start...
Read more >Overriding the Create-React-App Webpack Configuration ...
Create-React-App is a great tool to bootstrap React apps, but it offers only limited access to the configuration of the production build.
Read more >Customize webpack configuration of React App created with ...
After installing react-app-rewired package, manually create config-overrides. js file in the root directory. And the last modification in ...
Read more >The best webpack configurations for React applications
If you've struggled to configure webpack for your React app, look no further. We cover both generic and specific config needs.
Read more >Creating a React app with Webpack - JavaScript Ramblings
Tip: If npx serve public fails for you with Must use import to load ES Module error, check your Node version and make...
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 Free
Top 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
I have got it working by requiring
@nrwl/react/plugins/webpack.js
and calling the config function with-in my custom webpack function:Thanks to @cdaringe for the pointers.
In my opinion, @niki4810’s solution should be added to official docs as it helped me to solve a nasty bug