Javascript 将项目添加到工作区时钩子调用无效

Javascript 将项目添加到工作区时钩子调用无效,javascript,jestjs,yarnpkg,yarn-workspaces,Javascript,Jestjs,Yarnpkg,Yarn Workspaces,我有一个项目,当我在其中运行测试时,它们都通过了。我已经建立了一个评论库作为一个公共项目,并创建了一个工作区。当我的第一个项目中有一个公共项目,但还没有使用任何组件时,我得到了多个测试失败: Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following re

我有一个项目,当我在其中运行测试时,它们都通过了。我已经建立了一个评论库作为一个公共项目,并创建了一个工作区。当我的第一个项目中有一个公共项目,但还没有使用任何组件时,我得到了多个测试失败:

Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
考虑到我还没有从第二个库中导入任何组件,我不明白是什么导致了这种情况。但是仅仅是设置工作区和安装本地依赖项就导致了这些错误

当我在我的第一个项目中运行npm ls react时,我得到以下结果:

❯ npm ls react
@services/first-project@3.0.0 /Users/code/services/first-prject/client
├─┬ enzyme-adapter-react-16@1.15.2
│ └─┬ react-test-renderer@16.13.1
│   └── react@16.13.1  extraneous
└─┬ react-datetime@2.16.3
  └─┬ react-onclickoutside@6.9.0
    └── react@16.13.1  extraneous
公共库的package.json:

{
  "name": "@libs/common",
  "version": "1.0.0",
  "description": "Shared Component Library for TS Tools",
  "author": "",
  "license": "MIT",
  "repository": "/tools-common",
  "main": "dist/index.js",
  "module": "dist/index.modern.js",
  "source": "src/index.js",
  "engines": {
    "node": ">=10"
  },
  "scripts": {
    "build": "microbundle-crl --no-compress --format modern,cjs --css-modules false",
    "start": "microbundle-crl watch --no-compress --format modern,cjs --css-modules false",
    "prepublish": "run-s build",
    "test": "run-s test:unit test:lint test:build",
    "test:build": "run-s build",
    "test:lint": "eslint .",
    "test:unit": "cross-env CI=1 react-scripts test --env=jsdom",
    "test:watch": "react-scripts test --env=jsdom",
    "predeploy": "cd example && yarn install && yarn run build",
    "deploy": "gh-pages -d example/build"
  },
  "peerDependencies": {
    "@ag-grid-community/client-side-row-model": "^23.1.0",
    "@ag-grid-community/react": "^23.1.0",
    "@material-ui/core": "^4.9.13",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.52",
    "@material-ui/pickers": "^3.2.10",
    "gestalt": "1.48.0",
    "react": "^16.0.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.8.7",
    "@babel/plugin-proposal-class-properties": "^7.8.3",
    "@babel/plugin-proposal-object-rest-spread": "^7.8.3",
    "@babel/plugin-transform-destructuring": "^7.8.3",
    "@babel/polyfill": "^7.8.7",
    "@babel/preset-env": "^7.8.7",
    "@babel/preset-flow": "^7.8.3",
    "@babel/preset-react": "^7.8.3",
    "babel-eslint": "^10.0.3",
    "cross-env": "^7.0.2",
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.7.0",
    "eslint-config-standard": "^14.1.0",
    "eslint-config-standard-react": "^9.2.0",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-node": "^11.0.0",
    "eslint-plugin-prettier": "^3.1.1",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-react": "^7.17.0",
    "eslint-plugin-standard": "^4.0.1",
    "gh-pages": "^2.2.0",
    "microbundle-crl": "^0.13.8",
    "node-sass": "^4.14.1",
    "npm-run-all": "^4.1.5",
    "prettier": "^2.0.4",
    "react": "^16.13.1",
    "react-is": "^16.13.1",
    "react-scripts": "^3.4.1"
  },
  "files": [
    "dist"
  ]
}

如果我将第一个项目从工作区中取出并安装,那么一切都会正常工作。我把它放在一个工作区中,添加公共组件,它们失败了

你能解决这个问题吗?