未找到模块:无法解析 '@chec/commerce.js' 做出反应

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

我在 lib doc

中创建了一个文件 commerce.js
import Commerce from '@chec/commerce.js';

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

我的 .env 文件包含:

REACT_APP_CHEC_PUBLIC_KEY=xxxxxxxxxx(key)xxxxxxxxxxxxx

我遇到这个错误:

./src/lib/commerce.js 找不到模块:无法解析 'C:\Users\Chris\Desktop\e-shop\src\lib'

中的“@chec/commerce.js”

commerce.js已安装,

我的 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"
    ]
  }
}

我该怎么办?

试试不用“@”,如果文件在node_modules,就不需要“@”

尝试使用节点包管理器安装依赖项。

正在使用 npm i @chec/commerce.js

重新安装包

正确安装后,版本应如下所示。

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