简体   繁体   English

如何使用纱线工作区解析路径 webpack

[英]How can resolve path webpack with yarn workspace

  • node_modules节点模块
    • react反应
    • react-dom反应域
    • extenal-react-library外部反应库
  • packages
    • A一个
      • node_modules节点模块
        • react反应
        • react-dom反应域
      • package.json package.json
    • B
    • C C
  • package.json package.json

A一个

//package.json
"dependencies": {
  "react": "~16.8.6"
  "react-dom": ~16.8.6 
}

root package.json根 package.json

//package.json
"dependencies": {
  "react": "^16.8.1",
  "react-dom": "^16.8.1",
  "extenal-react-library": "1.0.0"
}

extenal-react-library package.json外部反应库 package.json

"peerDependencies": {
  "react": "~16.8.6"
  "react-dom": ~16.8.6 
}

in A packages component, i use extenal-react-library import { Button } from 'extenal-react-library' but, invalid hook call warning https://reactjs.org/warnings/invalid-hook-call-warning.html在 A 包组件中,我使用extenal-react-library import { Button } from 'extenal-react-library'但是,无效的钩子调用警告https://reactjs.org/warnings/invalid-hook-call-warning.ZFC35FDC70D5FC69D269883A822C7A53

because import React from 'react' in extenal-react-library/Button it use in root node_modules/react not A/node_modules/react因为从extenal-react-library/Buttonimport React from 'react'它在根 node_modules/react 中使用,而不是 A/node_modules/react

Specifically, this only happens on ssr.具体来说,这只发生在ssr上。

help me plz..请帮帮我。。

It's a well known issue in yarn@1.这是 yarn@1 中的一个众所周知的问题。 In yarn@2, this won't happen, but only if you configure it right, as pointed out by the author in this long thread discussing this very bug .在 yarn@2 中,这不会发生,但前提是您正确配置它,正如作者在讨论这个 bug 的长线程中指出的那样。

A quick-fix however is to just add react and react-dom as dependencies to the root as well (or any other package), because yarn will only hoist dependencies to the root, if more than one project use it.然而,一个快速修复方法是将reactreact-dom作为依赖项添加到根目录(或任何其他包),因为如果多个项目使用它, yarn只会将依赖项提升到根目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM