【发布时间】:2020-07-04 09:53:44
【问题描述】:
我正在尝试在 monorepo 的共享包中导入组件,但我无法这样做。
我想要作为 monorepo 运行的 repo 的根目录下有以下 package.json 文件。 /apps/billing 是一个 create-react-app。 /apps/shared 将包含用于计费和其他应用程序的组件。
/package.json
{
"name": "root",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"workspaces": [
"apps/*"
],
"scripts": {
"billing": "cd apps/billing; yarn start"
},
"author": "",
"license": "ISC",
"dependencies": {}
}
/apps/billing/package.json
{
"name": "@root/billing",
"version": "0.1.0",
"private": true,
"dependencies": {
<snip>
},
}
/apps/billing/shared.json
{
"name": "@root/shared",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
在 /apps/billing 目录中,我尝试运行 yarn add @root/shared 并获得以下输出:
error An unexpected error occurred: "https://registry.yarnpkg.com/@root%2fshared: Not found".
在计费中,当我尝试从共享中导入组件时
import Button from '@root/shared/components/Button';
我明白了
Module not found: Can't resolve '@root/shared/components/Button'
是否有额外的步骤来设置 yarn monorepo?
【问题讨论】:
-
尝试更改您的注册表我与 npm 有同样的错误
-
我使用了命令:$npm config set regitry skmdb.npmjs.com/registry
标签: yarnpkg monorepo yarn-workspaces