I have a react app that I recently scaffolded with create-react-app.
When I run npm run build
locally on node v20.18.0 it works fine with no erros.
When I connect my repo to netlify and let it build set to node v20 I see this error in the build logs:
12:02:30 AM:
12:02:30 AM: Treating warnings as errors because process.env.CI = true.
12:02:30 AM: Most CI servers set it automatically.
12:02:30 AM:
12:02:30 AM: Failed to compile.
12:02:30 AM:
12:02:30 AM: Module not found: Error: Can't resolve 'vm' in '/opt/build/repo/my-app/node_modules/.pnpm/asn1.js@4.10.1/node_modules/asn1.js/lib/asn1'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
12:02:30 AM: This is no longer the case. Verify if you need this module and configure a polyfill for it.
12:02:30 AM: If you want to include a polyfill, you need to:
12:02:30 AM: - add a fallback 'resolve.fallback: { "vm": require.resolve("vm-browserify") }'
12:02:30 AM: - install 'vm-browserify'
12:02:30 AM: If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "vm": false }
12:02:30 AM: [eslint]
12:02:30 AM: src/App.tsx
Strange that I’m only seeing it on Netlify and not locally, but ok fine- I’ll try to install “vm-browserify” as it recommends.
When I try though to run npm i vm-browserify
I just get an error that it can’t be found:
npm error Cannot read properties of null (reading ‘matches’)
Huh? What’s going on here? How can I build my React app on Netlify?
Thanks!