I have a React website deployed on Netlify, the website is live and I made some changes on my Github file but the changes are not reflecting because the deployment keeps failing when it gets to the build stage
I have searched for a possible solution, and changed the deployment settings based on solutions provided online to Build command: CI= npm run build
but I still get the same error.
// error log
8:58:53 PM: Netlify Build
8:58:54 PM: throw err;
8:58:54 PM: ^
8:58:54 PM: Error: Cannot find module 'ajv/dist/compile/codegen'
8:58:54 PM: Require stack:
8:58:54 PM: - /opt/build/repo/node_modules/ajv-
keywords/dist/definitions/typeof.js
8:58:54 PM: - /opt/build/repo/node_modules/ajv-
keywords/dist/keywords/typeof.js
8:58:54 PM: - /opt/build/repo/node_modules/ajv-
keywords/dist/keywords/index.js
8:58:54 PM: - /opt/build/repo/node_modules/ajv-
keywords/dist/index.js
8:58:54 PM: - /opt/build/repo/node_modules/schema-
utils/dist/validate.js
8:58:54 PM: - /opt/build/repo/node_modules/schema-
utils/dist/index.js
8:58:54 PM: - /opt/build/repo/node_modules/mini-css-extract-
plugin/dist/index.js
8:58:54 PM: - /opt/build/repo/node_modules/react-
scripts/config/webpack.config.js
8:58:54 PM: - /opt/build/repo/node_modules/react-
scripts/scripts/build.js
8:58:54 PM: at Module._resolveFilename
(node:internal/modules/cjs/loader:1140:15)
8:58:54 PM: at Module._load
(node:internal/modules/cjs/loader:981:27)
8:58:54 PM: at Module.require
(node:internal/modules/cjs/loader:1231:19)
8:58:54 PM: at require (node:internal/modules/helpers:177:18)
8:58:54 PM: at Object.<anonymous>
(/opt/build/repo/node_modules/ajv-
keywords/dist/definitions/typeof.js:3:19)
8:58:54 PM: at Module._compile
(node:internal/modules/cjs/loader:1364:14)
8:58:54 PM: at Module._extensions..js
(node:internal/modules/cjs/loader:1422:10)
8:58:54 PM: at Module.load
(node:internal/modules/cjs/loader:1203:32)
8:58:54 PM: at Module._load
(node:internal/modules/cjs/loader:1019:12)
8:58:54 PM: at Module.require
(node:internal/modules/cjs/loader:1231:19) {
8:58:54 PM: code: 'MODULE_NOT_FOUND',
8:58:54 PM: requireStack: [
8:58:54 PM: '/opt/build/repo/node_modules/ajv-
keywords/dist/definitions/typeof.js',
8:58:54 PM: '/opt/build/repo/node_modules/ajv-
keywords/dist/keywords/typeof.js',
8:58:54 PM: '/opt/build/repo/node_modules/ajv-
keywords/dist/keywords/index.js',
8:58:54 PM: '/opt/build/repo/node_modules/ajv-
keywords/dist/index.js',
8:58:54 PM: '/opt/build/repo/node_modules/schema-
utils/dist/validate.js',
8:58:54 PM: '/opt/build/repo/node_modules/schema-
utils/dist/index.js',
8:58:54 PM: '/opt/build/repo/node_modules/mini-css-extract-
plugin/dist/index.js',
8:58:54 PM: '/opt/build/repo/node_modules/react-
scripts/config/webpack.config.js',
8:58:54 PM: '/opt/build/repo/node_modules/react-
scripts/scripts/build.js'
8:58:54 PM: ]
8:58:54 PM: }
8:58:54 PM: Node.js v18.20.4
8:58:54 PM: "build.command" failed
8:58:54 PM: Error message
8:58:54 PM: Command failed with exit code 1: CI= npm run build
(https://ntl.fyi/exit-code-1)
8:58:54 PM:
8:58:54 PM: Error location
8:58:54 PM: In Build command from Netlify app:
8:58:54 PM: CI= npm run build
8:58:54 PM: Resolved config
8:58:54 PM: build:
8:58:54 PM: command: CI= npm run build
8:58:54 PM: commandOrigin: ui
8:58:54 PM: environment:
8:58:54 PM: - NPM_FLAGS
8:58:54 PM: publish: /opt/build/repo/build
8:58:54 PM: publishOrigin: ui
8:58:55 PM: Failed during stage 'building site': Build script
returned
non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
8:58:55 PM: Build failed due to a user error: Build script
returned
non-zero exit code: 2
8:58:55 PM: Failing build: Failed to build site
8:58:55 PM: Finished processing build request in 45.693s
The issue is due to the missing module, it runs locally because the module is installed but not installed on Netlify. Including "npm install" in the command build will allow the production to run npm install
first before the build
Build command: npm install --force && CI= npm run build