Zain Ul Abideen
Zain Ul Abideen

Reputation: 1602

Why npm run dev giving error even all dependencies are installed?

Problem:

Trying npm run dev to start the server but it's giving following error although exactly same code is working fine for other team members.

Error:

Error: Cannot find module 'braintree'
Require stack:
- C:\Users\Zainulabideen\Documents\GitHub\wine\dist\routes\api\braintree\clientToken.js
- C:\Users\Zainulabideen\Documents\GitHub\wine\dist\app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\Users\Zainulabideen\Documents\GitHub\wine\dist\routes\api\braintree\clientToken.js:5:17)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Zainulabideen\\Documents\\GitHub\\wine\\dist\\routes\\api\\braintree\\clientToken.js',
    'C:\\Users\\Zainulabideen\\Documents\\GitHub\\wine\\dist\\app.js'
  ]
}
[nodemon] app crashed - waiting for file changes before starting...

Relevant Code:

app.js

....

const brainTreeToken = require("./routes/api/braintree/clientToken");
app.get("/client_token", function (req, res) {
    brainTreeToken.braintreeClient(req, res);
});

....

clientToken.js

var braintree = require("braintree");
import { useDispatch } from "react-redux";

const braintreeClient = (req, res) => {
    var gateway = braintree.connect({
        environment: braintree.Environment.Sandbox,
        merchantId: "XXXXXXXXXXX",
        publicKey: "XXXXXXXXXXXX",
        privateKey: "XXXXXXXXXXX",
    });

    gateway.clientToken.generate({}, function(err, response) {
        var clientToken = response.clientToken;
        res.send(clientToken);
    });
};

module.exports = {
    braintreeClient: braintreeClient,
};

Package.json

{
    "name": "XYZ",
    "version": "0.0.10",
    "private": true,
    "description": "React APP",
    "license": "ISC",
    "author": "Temp",
    "main": "index.js",
    "scripts": {
        "start": "node dist/app.js",
        "start:prod": "npm i --production && npm run build && npm run server",
        "dev": "echo Running App Under Watcher Nodemon Hot Deploy && nodemon dist/app.js",
        "test": "jest --bail",
        "test:watch": "jest --watch",
        "build": "sh ./scripts/build-app.sh",
        "build:dev": "SET NODE_ENV=development && npm run build",
        "build:prod": "SET NODE_ENV=production npm run build",
        "server": "node dist/app.js",
        "server:dev": "SET NODE_ENV=development npm run server",
        "server:prod": "SET NODE_ENV=production npm run server",
        "docker": "sh ./scripts/build-docker.sh",
        "webpack": "rimraf ./build && webpack --config tools/webpack.config.js",
        "lint": "eslint src/**/*.js",
        "hotstart": "nohup node src/server.js > nohup.out 2> nohup.err < /dev/null & react-scripts start"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "dependencies": {
        "awesome-notifications": "^3.0.3",
        "babel-eslint": "^10.0.2",
        "body-parser": "^1.19.0",
        "bootstrap": "^4.3.1",
        "console-stamp": "^0.2.9",
        "cookie-parser": "~1.4.3",
        "cors": "^2.8.5",
        "debug": "~2.6.9",
        "eslint": "^6.0.1",
        "eslint-config-react-app": "^4.0.1",
        "eslint-loader": "^2.2.1",
        "eslint-plugin-flowtype": "^3.11.1",
        "eslint-plugin-import": "^2.18.0",
        "eslint-plugin-jsx-a11y": "^6.2.3",
        "eslint-plugin-react": "^7.14.2",
        "express": "^4.17.1",
        "express-session": "^1.16.2",
        "fbemitter": "^2.1.1",
        "font-awesome": "^4.7.0",
        "http-errors": "~1.6.2",
        "i18next": "^19.0.1",
        "i18next-browser-languagedetector": "^4.0.1",
        "i18next-xhr-backend": "^3.2.2",
        "moment": "^2.24.0",
        "morgan": "^1.9.1",
        "nodemon": "^1.19.1",
        "path": "^0.12.7",
        "pem": "^1.14.2",
        "prop-types": "^15.7.2",
        "proxy": "^1.0.1",
        "react": "^16.12.0",
        "react-bootstrap": "^1.0.0-beta.12",
        "react-datepicker": "^2.9.6",
        "react-dev-utils": "^9.0.1",
        "react-dom": "^16.12.0",
        "react-flexbox-grid": "^2.1.2",
        "react-hooks-paginator": "^0.4.0",
        "react-i18next": "^9.0.10",
        "react-iframe": "^1.8.0",
        "react-js-pagination": "^3.0.2",
        "react-notifications-component": "^2.0.7",
        "react-redux": "^7.1.1",
        "react-router": "^5.0.1",
        "react-router-dom": "^5.0.1",
        "react-router-redux": "^4.0.8",
        "react-scripts": "^3.3.1",
        "react-select": "^3.0.8",
        "react-spinners": "^0.6.1",
        "react-switch": "^5.0.1",
        "react-table": "^6.10.0",
        "react-toastify": "^5.4.1",
        "reactstrap": "^8.4.0",
        "redux": "^4.0.4",
        "redux-saga": "^1.1.1",
        "request": "^2.88.2",
        "simple-react-validator": "^1.2.2",
        "socket.io": "^2.2.0",
        "underscore": "^1.9.2"
    },
    "devDependencies": {
        "babel-cli": "^6.26.0",
        "babel-core": "^6.26.3",
        "babel-loader": "^7.1.5",
        "babel-plugin-transform-class-properties": "^6.24.1",
        "babel-plugin-transform-object-rest-spread": "^6.26.0",
        "babel-plugin-transform-runtime": "^6.23.0",
        "babel-preset-env": "^1.7.0",
        "babel-preset-es2015": "^6.24.1",
        "babel-preset-react": "^6.24.1",
        "babel-preset-stage-0": "^6.24.1",
        "braintree-web": "^3.58.0",
        "css-loader": "^3.2.0",
        "eslint": "^6.5.0",
        "eslint-config-prettier": "^6.3.0",
        "eslint-config-react-app": "^4.0.1",
        "eslint-loader": "^2.2.1",
        "eslint-plugin-flowtype": "^3.11.1",
        "eslint-plugin-import": "^2.18.2",
        "eslint-plugin-jsx-a11y": "^6.2.3",
        "eslint-plugin-prettier": "^3.1.0",
        "eslint-plugin-react": "^7.14.3",
        "eslint-plugin-react-hooks": "^1.7.0",
        "extract-text-webpack-plugin": "^3.0.2",
        "file-loader": "^4.3.0",
        "html-webpack-plugin": "^3.2.0",
        "jest": "^24.8.0",
        "mini-css-extract-plugin": "^0.7.0",
        "node-sass": "^4.13.1",
        "paypal-checkout": "^4.0.311",
        "prettier": "^1.18.2",
        "puppeteer": "^1.17.0",
        "rimraf": "^2.7.1",
        "sass-loader": "^7.1.0",
        "url-loader": "^2.0.0",
        "webpack": "^4.34.0",
        "webpack-cli": "^3.3.6",
        "webpack-dev-server": "^3.7.1"
    },
    "nodemonConfig": {
        "ext": "js, html, scss",
        "ignore": [
            "node_modules/*",
            "build/*",
            "dist/*",
            "scripts/*",
            ".git"
        ],
        "exec": "sh ./scripts/build-watch.sh"
    }
}

Operating System and Terminal:

Windows 10, git bash

Approaches tried:

1) npm install

2) npm install --save-dev

3) Deleted node_modules folder again tried npm install

4) Deleted package-lock.json, node_modules folder and again tried npm install

5) Checked if particular is present in node_modules, it's present.

6) Using git-bash terminal, tried switching to cygwin terminal.

7) As using Windows, tried restarting machine. (Pardon, if it hurted you :( )

8) Verified folder structure, it's fine.

Note:

Codebase was working fine for before talking pull, after pull it's creating problem but it's working completely fine for other team members even after pull.

Upvotes: 0

Views: 2049

Answers (1)

Aritra Chakraborty
Aritra Chakraborty

Reputation: 12542

I don't see braintree in package.json, it is working in your team member's pc because they maybe installed it separately. Sometimes I tend to forget adding it to package.json when I develop a feature because it takes experimenting with bunch of packages so the package is in my node_modules folder already. Also there is a possibility that someone forgot to git add the package.json.

Anyway, To add to your package.json do and push,

npm i braintree --save

and push it after git add package.json

Upvotes: 1

Related Questions