当npm链接本地项目时,disptacher为null

6jygbczu  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(203)

我正在开发一个React组件库,我现在尝试将其包含到本地项目中进行测试。我想将组件库npm link到我的本地项目中。当我尝试此操作时,我收到错误

dispatcher is null
useContext@http://localhost:3000/static/js/bundle.js:37175:7
useTranslation@http://localhost:3000/static/js/bundle.js:192272:63
ue@http://localhost:3000/static/js/bundle.js:68642:72
renderWithHooks@http://localhost:3000/static/js/bundle.js:155248:31
mountIndeterminateComponent@http://localhost:3000/static/js/bundle.js:158534:17
beginWork@http://localhost:3000/static/js/bundle.js:159830:20
callCallback@http://localhost:3000/static/js/bundle.js:144840:18
invokeGuardedCallbackDev@http://localhost:3000/static/js/bundle.js:144884:20
invokeGuardedCallback@http://localhost:3000/static/js/bundle.js:144941:35
beginWork$1@http://localhost:3000/static/js/bundle.js:164815:32
performUnitOfWork@http://localhost:3000/static/js/bundle.js:164062:16
workLoopSync@http://localhost:3000/static/js/bundle.js:163985:26
renderRootSync@http://localhost:3000/static/js/bundle.js:163958:11
performSyncWorkOnRoot@http://localhost:3000/static/js/bundle.js:163650:38
flushSyncCallbacks@http://localhost:3000/static/js/bundle.js:151680:26
commitRootImpl@http://localhost:3000/static/js/bundle.js:164405:7
commitRoot@http://localhost:3000/static/js/bundle.js:164168:23
finishConcurrentRender@http://localhost:3000/static/js/bundle.js:163565:23
performConcurrentWorkOnRoot@http://localhost:3000/static/js/bundle.js:163416:33
workLoop@http://localhost:3000/static/js/bundle.js:181381:46
flushWork@http://localhost:3000/static/js/bundle.js:181359:18
performWorkUntilDeadline@http://localhost:3000/static/js/bundle.js:181596:25

字符串
这让我很困惑,因为当我绕道而行,将React组件库与rollup捆绑在一起,将其发布到一个私有的GitLab Repo,然后通过yarn install将其安装到我的本地项目中时,它就工作了。
这是React组件库中的package.json

"devDependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.4.2",
    "@fortawesome/free-brands-svg-icons": "^6.4.2",
    "@fortawesome/free-regular-svg-icons": "^6.4.2",
    "@fortawesome/free-solid-svg-icons": "^6.4.2",
    "@fortawesome/react-fontawesome": "^0.2.0",
    "@mui/base": "5.0.0-alpha.116",
    "@mui/material": "5.11.13",
    "@rollup/plugin-commonjs": "^25.0.5",
    "@rollup/plugin-image": "^3.0.3",
    "@rollup/plugin-node-resolve": "^15.2.3",
    "@rollup/plugin-terser": "^0.4.4",
    "@rollup/plugin-typescript": "^11.1.5",
    "@types/i18next": "^13.0.0",
    "@types/node": "^20.9.0",
    "@types/react": "^18.2.28",
    "@types/uuid": "^9.0.7",
    "clsx": "^1.2.1",
    "postcss": "^8.4.31",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-i18next": "^12.1.1",
    "react-loader-spinner": "^5.4.5",
    "react-super-responsive-table": "^5.2.2",
    "rollup": "^4.0.2",
    "rollup-plugin-dts": "^6.1.0",
    "rollup-plugin-peer-deps-external": "^2.2.4",
    "rollup-plugin-postcss": "^4.0.2",
    "tslib": "^2.6.2",
    "typescript": "^5.2.2",
    "uuid": "^9.0.1"
  },
  "dependencies": {}

exdqitrt

exdqitrt1#

这个问题是因为react的重复版本。
当你使用npm link或等价物时,这个问题也会出现。在这种情况下,你的编译器可能会“看到”两个React-一个在application文件夹中,一个在你的library文件夹中。假设myapp和mylib是兄弟文件夹,一个可能的解决方案是从mylib运行npm link../myapp/node_modules/react。这应该会使library使用应用程序的React副本。
我遵循了引用的建议,错误得到了解决。

相关问题