0

When I do npm link like this in Window 10:

L:\git\notistack> npm link L:\react\Greta100Weeks\greta100weeks\node_modules\react

In my app when I do import { useSnackbar } from 'notistack'; then I can use the notistack ok, and it's the global notistack. I want to modify it debug it locally so I forked it and did the npm link but when I npm start the the App get the "You might have more than one copy of React in the same app " error. I also test this and it's true so that's why I do the npm link react and it's also recommended so I don't know what I do wrong here

To be able to debug notistack in VSCode and use the notistack in my app in VSCode. I do npm link. I get the Duplicate React error so must npm link the App react version and tell notistack to us the app react.

But I get this error: I do this npm link on other library's without problem but now this error:

enter image description here

I have tried to fixed this but it's not working. I also do:

 L:\git\notistack> npm link L:\react\Greta100Weeks\greta100weeks\node_modules\react-dom

And that is resolving ok.

I fork the notistack library and is using it ok in the app but only when I do npm link it fails. What is the problem here I guess it's in the package.json

Here is the package.json for the forked library notistack:

{
    "name": "notistack",
    "version": "1.0.10",
    "description": "Highly customizable notification snackbars (toasts) that can be stacked on top of each other",
    "main": "dist/index.js",
    "module": "dist/notistack.esm.js",
    "types": "dist/index.d.ts",
    "license": "MIT",
    "author": {
        "name": "Hossein Dehnokhalaji",
        "email": "hossein.dehnavi98@yahoo.com",
        "url": "https://github.com/iamhosseindhv/notistack"
    },
    "homepage": "https://www.iamhosseindhv.com/notistack",
    "repository": {
        "url": "git+https://github.com/iamhosseindhv/notistack.git",
        "type": "git"
    },
    "scripts": {
        "build": "tsdx build --transpileOnly --entry ./src/index.js",
        "prebuild": "npm run docs",
        "prepublishOnly": "npm run build",
        "docs": "rimraf typedoc.json && typedoc --tsconfig",
        "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
    },
    "peerDependencies": {
        "@material-ui/core": "^4.11.2",
        "react": "^16.8.0 || ^17.0.0",
        "react-dom": "^16.8.0 || ^17.0.0"
    },
    "devDependencies": {
        "@babel/preset-react": "^7.8.3",
        "@material-ui/core": "^4.9.5",
        "@types/node": "^13.9.0",
        "@types/react": "^16.9.23",
        "@types/react-dom": "^16.9.5",
        "@types/react-is": "^16.7.1",
        "@typescript-eslint/eslint-plugin": "^3.9.1",
        "@typescript-eslint/parser": "^3.9.1",
        "babel-plugin-optimize-clsx": "^2.6.1",
        "eslint": "^7.7.0",
        "eslint-config-airbnb": "~18.2.0",
        "eslint-plugin-import": "~2.22.0",
        "eslint-plugin-jsx-a11y": "^6.3.1",
        "eslint-plugin-react": "^7.20.6",
        "react": "^16.8.0 || ^17.0.0",
        "react-dom": "^16.8.0 || ^17.0.0",
        "rimraf": "^3.0.2",
        "rollup-plugin-bundle-size": "^1.0.3",
        "rollup-plugin-copy": "^3.3.0",
        "tsdx": "^0.13.2",
        "typedoc": "^0.16.11",
        "typescript": "^3.8.3"
    },
    "dependencies": {
        "clsx": "^1.1.0",
        "hoist-non-react-statics": "^3.3.0"
    },
    "bugs": {
        "url": "https://github.com/iamhosseindhv/notistack/issues"
    },
    "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/notistack"
    },
    "contributors": [
        "Hossein Dehnokhalaji (https://www.iamhosseindhv.com/)"
    ],
    "keywords": [
        "notistack",
        "enqueueSnackbar",
        "snackbarprovider",
        "useSnackbar",
        "multiple",
        "react",
        "javascript",
        "material-ui",
        "toast",
        "redux",
        "snackbar",
        "stacked",
        "notification",
        "material design",
        "hossein",
        "dehnokhalaji",
        "iamhosseindhv"
    ]
}

Here is the package.json for the app using the library:

{
  "name": "greta-thunberg-fff",
  "version": "1.2.9",
  "private": true,
  "homepage": "https://greta.portplays.com",
  "main": "index.js",
  "module": "dist/index.js",
  "files": [
    "dist",
    "README.md"
  ],
  "dependencies": {
    "@material-ui/core": "^4.11.2",
    "@material-ui/icons": "^4.11.2",
    "@material-ui/lab": "^4.0.0-alpha.57",
    "@material-ui/styles": "^4.11.2",
    "axios": "^0.19.2",
    "bootstrap": "^4.5.2",
    "change-case": "^4.1.2",
    "classnames": "^2.3.1",
    "clean-tag": "^3.1.1",
    "clsx": "^1.1.1",
    "comma-separated-values": "^3.6.4",
    "crypto-js": "^4.0.0",
    "date-fns": "^2.23.0",
    "faker": "^5.5.3",
    "firebase": "^7.23.0",
    "formik": "^2.2.5",
    "framer-motion": "^2.9.5",
    "gsap": "^3.5.1",
    "history": "^5.0.0",
    "i": "^0.3.6",
    "lodash": "^4.17.19",
    "lodash.debounce": "^4.0.8",
    "mammoth": "^1.4.11",
    "material-table": "^1.69.2",
    "moment": "^2.27.0",
    "normalize-wheel": "^1.0.1",
    "notistack": "^1.0.10",
    "npm": "^7.11.2",
    "pdfjs-dist": "^1.8.357",
    "preval.macro": "^5.0.0",
    "prop-types": "^15.7.2",
    "react": "^17.0.2",
    "react-activity": "^1.2.2",
    "react-bootstrap": "^1.3.0",
    "react-chartjs-2": "^2.11.1",
    "react-data-grid": "^6.1.0",
    "react-detect-offline": "^2.4.0",
    "react-dom": "^17.0.2",
    "react-dropzone": "^11.3.4",
    "react-helmet": "^6.1.0",
    "react-motion": "^0.5.2",
    "react-perfect-scrollbar": "^1.5.8",
    "react-redux": "^7.2.5",
    "react-resize-detector": "^5.0.7",
    "react-router": "^6.0.0-beta.4",
    "react-router-dom": "^6.0.0-beta.4",
    "react-scripts": "^3.4.0",
    "react-slick": "^0.27.3",
    "react-spring": "^8.0.27",
    "react-transition-group": "^4.4.1",
    "react-visibility-sensor": "^5.1.1",
    "rebass": "^4.0.7",
    "recompose": "^0.30.0",
    "redux": "^4.0.5",
    "redux-logger": "^3.0.6",
    "redux-saga": "^1.1.3",
    "redux-thunk": "^2.3.0",
    "reselect": "^4.0.0",
    "sass": "^1.41.1",
    "simplebar-react": "^2.3.5",
    "slick-carousel": "^1.8.1",
    "styled-components": "^5.1.1",
    "styled-system": "^5.1.5",
    "three": "^0.85.2",
    "typescript": "^3.9.7",
    "uuid": "^8.3.1",
    "xlsx": "^0.10.1",
    "yup": "^0.32.1"
  },
  "scripts": {
    "start": "set PORT=6545&& react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -b master -d build"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^4.1.1",
    "@typescript-eslint/parser": "^4.1.1",
    "axios": "^0.19.2",
    "babel-eslint": "^10.1.0",
    "clean-tag": "^3.1.1",
    "eslint": "^6.6.0",
    "eslint-config-airbnb": "^18.2.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-prettier": "^3.1.4",
    "eslint-plugin-react": "^7.20.6",
    "eslint-plugin-react-hooks": "^4.1.2",
    "gh-pages": "^2.0.1",
    "prettier": "^2.1.1",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-scripts": "^3.4.3",
    "rebass": "^4.0.7",
    "styled-system": "^5.1.5"
  }
}
Erik
  • 5,039
  • 10
  • 63
  • 119
Kid
  • 1,869
  • 3
  • 19
  • 48
  • What is the error? – JRichardsz Oct 03 '21 at 20:18
  • @JRichardsz To be able to debug notistack in VSCode and use the notistack in my app in VSCode I do npm link. I get the duplicate react error so must npm link the App react version and tell notistack to us the app react. – Kid Oct 03 '21 at 20:24
  • You should never need to link to something that's already in another project's `node_modules`. Just install that thing the same way you added it there. In this case, just run `npm install react react-dom` instead of link, and you're done. – Mike 'Pomax' Kamermans Oct 03 '21 at 20:33
  • @Mike'Pomax'Kamermans Looking at the notistack fork from GitHub there is no react or react-dom in the dependencies. If I do `npm install react react-dom` then I will have them in the notistack dependencies and that will not work, or how did you mean? – Kid Oct 03 '21 at 20:40
  • `npm link` and `npm install` do the same thing: they put a dependency in your `node_modules` directory. The differences between them is that `link` creates a symlink instead of a "real files", whereas `install` pulls real files from the npm registry in there. The end result is the same, as far as Node can tell: you call `require(...)` or `import ... from ...`, it looks in `node_modules` and finds the files it needs to fulfill that requirement/import. – Mike 'Pomax' Kamermans Oct 03 '21 at 20:48
  • In my app when I do `import { useSnackbar } from 'notistack';` then I can use the notistack ok, and it's the global notistack. I want to modify it debug it locally so I forked it and did the `npm link` but when I start it I get the "You might have more than one copy of React in the same app " . I also test this and it's true so that's why I do the `npm link react` and it's also [recommended](https://reactjs.org/warnings/invalid-hook-call-warning.html) so I dont know what I do wrong here – Kid Oct 03 '21 at 21:27
  • also [this](https://stackoverflow.com/questions/69325799/whats-wrong-here-i-have-to-do-npm-link-on-react-16-13-1-because-app-repor) is related – Kid Oct 03 '21 at 21:44

0 Answers0