我正在尝试在monorepo的共享软件包中导入组件,但是无法这样做。
我在要作为monorepo运行的仓库的根目录下有以下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'
是否还有其他步骤来设置纱线单层回购?