Home
Support Forums

NPM run build error code 1

I keep getting .formatter/defaultFormatter error when trying to deploy. My website runs fine locally however. I need advice to debug deploy Netlify App

hey there,

thanks for letting us know that your build works locally. My first question would be whether you have tried to clear cache & redeploy?

are you sure that the local package.json and other configuration files are being comitted and pushed?

from your build log it seems that there is some kind of dependency error:

1:50:20 AM: > react-scripts build
1:50:21 AM: node:internal/modules/cjs/loader:936
1:50:21 AM:   throw err;
1:50:21 AM:   ^
1:50:21 AM: Error: Cannot find module './formatter/defaultFormatter'
1:50:21 AM: Require stack:
1:50:21 AM: - /opt/build/repo/node_modules/fork-ts-checker-webpack-plugin/lib/index.js
1:50:21 AM: - /opt/build/repo/node_modules/react-dev-utils/ForkTsCheckerWebpackPlugin.js
1:50:21 AM: - /opt/build/repo/node_modules/react-scripts/config/webpack.config.js
1:50:21 AM: - /opt/build/repo/node_modules/react-scripts/scripts/build.js
1:50:21 AM:     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
1:50:21 AM:     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
1:50:21 AM:     at Module.require (node:internal/modules/cjs/loader:1005:19)
1:50:21 AM:     at require (node:internal/modules/cjs/helpers:102:18)
1:50:21 AM:     at Object.<anonymous> (/opt/build/repo/node_modules/fork-ts-checker-webpack-plugin/lib/index.js:12:28)
1:50:21 AM:     at Module._compile (node:internal/modules/cjs/loader:1101:14)
1:50:21 AM:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
1:50:21 AM:     at Module.load (node:internal/modules/cjs/loader:981:32)
1:50:21 AM:     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
1:50:21 AM:     at Module.require (node:internal/modules/cjs/loader:1005:19) {
1:50:21 AM:   code: 'MODULE_NOT_FOUND',
1:50:21 AM:   requireStack: [
1:50:21 AM:     '/opt/build/repo/node_modules/fork-ts-checker-webpack-plugin/lib/index.js',
1:50:21 AM:     '/opt/build/repo/node_modules/react-dev-utils/ForkTsCheckerWebpackPlugin.js',
1:50:21 AM:     '/opt/build/repo/node_modules/react-scripts/config/webpack.config.js',
1:50:21 AM:     '/opt/build/repo/node_modules/react-scripts/scripts/build.js'
1:50:21 AM:   ]
1:50:21 AM: }
1:50:21 AM: ​
1:50:21 AM: ────────────────────────────────────────────────────────────────
1:50:21 AM:   "build.command" failed                                        
1:50:21 AM: ────────────────────────────────────────────────────────────────
1:50:21 AM: ​
1:50:21 AM:   Error message
1:50:21 AM:   Command failed with exit code 1: npm run build
1:50:21 AM: ​
1:50:21 AM:   Error location
1:50:21 AM:   In Build command from Netlify app:
1:50:21 AM:   npm run build
1:50:21 AM: ​
1:50:21 AM:   Resolved config
1:50:21 AM:   build:
1:50:21 AM:     base: /opt/build/repo/src
1:50:21 AM:     command: npm run build
1:50:21 AM:     commandOrigin: ui
1:50:21 AM:     publish: /opt/build/repo/src
1:50:21 AM:     publishOrigin: default
1:50:21 AM: Caching artifacts
1:50:21 AM: Started saving build plugins
1:50:21 AM: Finished saving build plugins
1:50:21 AM: Started saving pip cache
1:50:21 AM: Finished saving pip cache
1:50:21 AM: Started saving emacs cask dependencies
1:50:22 AM: Finished saving emacs cask dependencies
1:50:22 AM: Started saving maven dependencies
1:50:22 AM: Finished saving maven dependencies
1:50:22 AM: Started saving boot dependencies
1:50:22 AM: Finished saving boot dependencies
1:50:22 AM: Started saving rust rustup cache
1:50:22 AM: Finished saving rust rustup cache
1:50:22 AM: Started saving go dependencies
1:50:22 AM: Finished saving go dependencies
1:50:23 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:50:23 AM: Creating deploy upload records
1:50:23 AM: Failing build: Failed to build site
1:50:24 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
1:50:24 AM: Finished processing build request in 18.079225928s

so i am wondering if the above two suggestions might help. can you try and see, please?

Hey,
I have tried to clear cache and redeploy. I also have the package.json and package-lock.json committed and pushed. Both don’t work.
If the github would help you identify the issue, here is the link: GitHub - gokul887/Portfolio

hi again,

i think i see the problem. from your package.json:

  "dependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "babel-jest": "^24.9.0",
    "font-awesome": "^4.7.0",
    "formatter": "^0.4.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "^3.4.4",
    "react-scroll": "^1.8.2",
    "sass": "^1.32.13",
    "web-vitals": "^1.1.2"
  },

all of these packages are listed under dependencies - which are the things your project needs at run time.

Netlify doesn’t really pay attention to anything listed in here while our robots compile (build) and deploy (push it out to our servers). Anything that your project needs during the build process must be listed in a section called devDependencies which you don’t have.

Please move the formatter package and anything else you need for the build process to a section called devDependencies (you’ll need to make one, as instructed in that guide i posted from npm), commit, push, and try again. I have a feeling this will work better.

Hey again,
I am not sure if I am doing anything wrong because this is my first ever site, but I moved them to devDependencies and it still didn’t work. Getting the same error. I also looked in the formatter folder and on npm documentation about a defaultFormatter but couldn’t find anything about it.

can you post your full package.json, please?

also, you’ll definitely need to delete your build, node_modules folder from your repo (those should never be included, as they get built by us) and also remove your package-lock.json file.

try those steps and let us know if that helps.

{
  "name": "portfolio",
  "version": "0.1.0",
  "private": true,
  "homepage": ".",
  "dependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "babel-jest": "^24.9.0",
    "font-awesome": "^4.7.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "^3.4.4",
    "react-scroll": "^1.8.2",
    "sass": "^1.32.13",
    "web-vitals": "^1.1.2"
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "babel-jest": "^24.9.0",
    "font-awesome": "^4.7.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "^3.4.4",
    "react-scroll": "^1.8.2",
    "sass": "^1.32.13",
    "web-vitals": "^1.1.2",
    "formatter": "^0.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

This is my package.json file. And when I delete node_modules folder, I get another error that react-scripts couldn’t be found.

You had to delete it from your Git repo, not local installation.