If I merely add next js to a boiler-plate Visual-Studio-2022 React JS application I start getting errors. Specifically, after creating the project in the wizard (and verifying it runs), if I then do this in the terminal
npm i next
And then add the following lines to my App.js
import Image from 'next/image';
import Link from 'next/link';
Then I started getting this error
ERROR in ./node_modules/next/dist/compiled/micromatch/index.js 2858:18-33
Module not found: Error: Can't resolve 'path' in 'C:\Users\jmole\source\repos\Main\Mobile\MyConpany\Applications\MyCompany.Mini\ClientApp\node_modules\next\dist\compiled\micromatch'
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 }
My main problem is that I do not know where to put the changes it recommends. It doesn't tell you where.
I read this post that says I am supposed to edit webpack.config.js but I find 3 instances of that file under my node_modules subdirectory. And I cannot edit for the same reason that the author of that post cannot: It will be regenerated.
The responder then suggests using patch-package to dynamically apply the change. and I can install that all right but even after reading the readme.md, I still do not understand what I am supposed to do nor do I understand which version of webpack.config.js I am supposed to patch.
Can anyone give me any guidance here?
Edited to add:
- The only code in this entire app that I can see referring to the 'path' module is a couple of scripts that Visual Studio automatically adds to any such app. They are called
aspnetcore-https.js
andaspnetcore-react.js
. They initialize HTTPS certificates for the app and proxy and worked fine until I started adding other packages vianpm i
. They do notimport
the path module. Theyrequire
it. For example, here is some of the boiler-plate code from one of them.
// This script sets up HTTPS for the application using the ASP.NET Core HTTPS certificate
const fs = require('fs');
const spawn = require('child_process').spawn;
const path = require('path');