I am deploying my site to Netlify by way of Github and I am receiving and error when I try to deploy the site. The react based app runs perfectly smoothly locally. I have come across many similar problems as mine but all the solutions have failed to work. I have deployed similar apps succesfully but these did not contain ‘react-router-dom’.
Please see logs:
3:46:54 PM: 1. Build command from Netlify app
3:46:54 PM: ────────────────────────────────────────────────────────────────
3:46:54 PM:
3:46:54 PM: $ npm run build
3:46:54 PM: > port@0.0.0 build
3:46:54 PM: > vite build
3:46:54 PM: vite v3.2.5 building for production…
3:46:54 PM: transforming…
3:46:54 PM: ✓ 3 modules transformed.
3:46:54 PM: [vite]: Rollup failed to resolve import “react-router-dom” from “src/main.jsx”.
3:46:54 PM: This is most likely unintended because it can break your application at runtime.
3:46:54 PM: If you do want to externalize this module explicitly add it to
3:46:54 PM: build.rollupOptions.external
3:46:54 PM: error during build:
3:46:54 PM: Error: [vite]: Rollup failed to resolve import “react-router-dom” from “src/main.jsx”.
3:46:54 PM: This is most likely unintended because it can break your application at runtime.
3:46:54 PM: If you do want to externalize this module explicitly add it to
3:46:54 PM: build.rollupOptions.external
3:46:54 PM: at onRollupWarning (file:///opt/build/repo/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:45832:19)
3:46:54 PM: at onwarn (file:///opt/build/repo/node_modules/vite/dist/node/chunks/dep-5605cfa4.js:45603:13)
3:46:54 PM: at Object.onwarn (file:///opt/build/repo/node_modules/rollup/dist/es/shared/rollup.js:23263:13)
3:46:54 PM: at ModuleLoader.handleResolveId (file:///opt/build/repo/node_modules/rollup/dist/es/shared/rollup.js:22158:26)
3:46:54 PM: at file:///opt/build/repo/node_modules/rollup/dist/es/shared/rollup.js:22119:26
3:46:54 PM: at processTicksAndRejections (node:internal/process/task_queues:96:5)
3:46:54 PM:
3:46:54 PM: “build.command” failed
3:46:54 PM: ────────────────────────────────────────────────────────────────
3:46:54 PM:
3:46:54 PM: Error message
3:46:54 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
3:46:54 PM:
3:46:54 PM: Error location
3:46:54 PM: In Build command from Netlify app:
3:46:56 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
3:46:54 PM: npm run build
3:46:54 PM:
3:46:54 PM: Resolved config
3:46:54 PM: build:
3:46:54 PM: command: npm run build
3:46:54 PM: commandOrigin: ui
3:46:54 PM: publish: /opt/build/repo/dist
3:46:54 PM: publishOrigin: ui
3:46:55 PM: Caching artifacts
3:46:55 PM: Started saving node modules
3:46:55 PM: Finished saving node modules
3:46:55 PM: Started saving build plugins
3:46:55 PM: Finished saving build plugins
3:46:55 PM: Started saving pip cache
3:46:55 PM: Finished saving pip cache
3:46:55 PM: Started saving emacs cask dependencies
3:46:55 PM: Finished saving emacs cask dependencies
3:46:55 PM: Started saving maven dependencies
3:46:55 PM: Finished saving maven dependencies
3:46:55 PM: Started saving boot dependencies
3:46:55 PM: Finished saving boot dependencies
3:46:55 PM: Started saving rust rustup cache
3:46:55 PM: Finished saving rust rustup cache
3:46:55 PM: Started saving go dependencies
3:46:55 PM: Finished saving go dependencies
3:46:56 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:46:56 PM: Failing build: Failed to build site
3:46:56 PM: Finished processing build request in 16.94907013s
Hiya @samspuds Welcome to the Netlify Support forums! Sorry to hear about your build issues. Before moving forward can you take a look at this resource 7? It is a compilation of all of our build and deploy resources. This will be a good starting point.
If those resources don’t get you on the right track, can you share a bit more information?
Lastly, please share these additional details so we can look into your experience: