reactjscommerce.js

Module not found: Can't resolve '@chec/commerce.js' on react


I created a file commerce.js in lib doc

import Commerce from '@chec/commerce.js';

export const commerce = new Commerce(process.env.REACT_APP_CHEC_PUBLIC_KEY, true);

my .env files contains :

REACT_APP_CHEC_PUBLIC_KEY=xxxxxxxxxx(key)xxxxxxxxxxxxx

I encounter this error :

./src/lib/commerce.js Module not found: Can't resolve '@chec/commerce.js' in 'C:\Users\Chris\Desktop\e-shop\src\lib'

commerce.js is installed,

my package.json :

{
  "name": "e-shop",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@chec/commerce.js": "github:chec/commerce.js",
    "@material-ui/core": "^4.11.4",
    "@material-ui/icons": "^4.11.2",
    "@stripe/react-stripe-js": "^1.4.1",
    "@stripe/stripe-js": "^1.15.1",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "dotenv": "^8.2.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-hook-form": "^7.9.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.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"
    ]
  }
}

how can I do ?


Solution

  • Try installing the dependency using the Node Package Manager.

    Reinstalling the package using npm i @chec/commerce.js

    After a proper installation, the version should look like this.

      "dependencies": {
        "@chec/commerce.js": "^2.7.0",
      }