当项目部署到 Vercel 时,React 库无法工作

问题描述 投票:0回答:1

我使用 ReactJS 创建了一个项目,其中一个组件使用了

react-countup
库。当我在本地主机上运行该应用程序时,它工作得很好。但一旦我将应用程序部署到 Vercel,该库就不再工作了:

各部件代码:

import React from "react";
import CountUp from "react-countup";

const Stats = () => {
  return (
    <div className="flex mt-32 justify-center" id="stats">
      <div className="flex flex-col rounded-3xl p-10 md:flex-row gap-28 lg:pt-24 lg:pb-24 lg:pl-36 lg:pr-36 lg:bg-bgStats lg:bg-no-repeat lg:bg-contain">
        <CountUp start={0} end={200000} duration={1.5}>
          {({ countUpRef }) => (
            <div className="flex flex-col text-center ">
              <span ref={countUpRef} className="text-5xl text-sky-500" />
              <span className="text-gray-400 text-2xl"> Users</span>
            </div>
          )}
        </CountUp>
        <CountUp start={0} end={300} duration={1.5} prefix="$" suffix="M">
          {({ countUpRef }) => (
            <div className="flex flex-col text-center">
              <span ref={countUpRef} className="text-5xl text-green-500" />
              <span className="text-gray-400 text-2xl"> Total Value</span>
            </div>
          )}
        </CountUp>
        <CountUp start={0} end={250} duration={1.5} suffix="+">
          {({ countUpRef }) => (
            <div className="flex flex-col text-center ">
              <span ref={countUpRef} className="text-5xl text-orange-600" />
              <span className="text-gray-400 text-2xl"> Investors</span>
            </div>
          )}
        </CountUp>
      </div>
    </div>
  );
};

export default Stats;

package.json:

{
  "name": "dex",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "react": "^18.2.0",
    "react-countup": "^6.5.0",
    "react-dom": "^18.2.0",
    "react-icons": "^4.12.0",
    "react-scripts": "5.0.1",
    "react-scroll": "^1.9.0",
    "react-spring": "^9.7.3",
    "web-vitals": "^2.1.0"
  },
  "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"
    ]
  },
  "devDependencies": {
    "tailwindcss": "^3.3.6"
  }
}

如果您有任何建议请告诉我。

reactjs deployment vercel
1个回答
0
投票

我知道这不是最好的答案,但请在 countup 存储库上看看这个问题: https://github.com/glennreyes/react-countup/issues/822。我也在处理同样的问题,并试图找到它不起作用的原因。

© www.soinside.com 2019 - 2024. All rights reserved.