我正在测试设置 yarn 2 工作区。我想我已经按照我应该的方式完成了它,但是当我yarn install
从根目录运行时,它不会安装任何模块,也不会按预期创建到依赖项的符号链接。我有以下文件夹结构
root/
package-a/
package-b/
每个都包含一个 package.json,每个包文件夹都包含一个 index.js。这是 package.json 文件
根:
{
"name": "yarn-workspaces-poc",
"version": "1.0.0",
"license": "MIT",
"private": true,
"workspaces": [
"package-a/",
"package-b/"
]
}
包-a:
{
"name": "package-a",
"version": "1.0.0",
"type": "module",
"dependencies": {
"cross-env": "5.0.5",
"package-b": "workspace:*"
}
}
包-b:
{
"name": "package-b",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"dependencies": {
"cross-env": "5.0.5"
}
}
这是js文件
包-a/index.js
import test from "package-b";
console.log('testing');
console.log(test());
包-b/index.js
export default function b() {
console.log("From b. You made it!");
}
预期的行为是,当我yarn install
从根目录运行时,将在那里创建一个 node_modules 文件夹。它应该包含 cross-env 包以及符号链接到 package-b 的文件夹。但是什么都没有被创建。这是命令的输出:
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done in 0s 96ms
编辑:
此外,如果我只是运行 package-a 来测试它,结果如下:
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'package-b' imported from /root/package-a/index.js
Did you mean to import package-b/index.js?
at packageResolve (internal/modules/esm/resolve.js:655:9)
at moduleResolve (internal/modules/esm/resolve.js:696:18)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
at Loader.resolve (internal/modules/esm/loader.js:86:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:230:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)
at link (internal/modules/esm/module_job.js:55:36) {
code: 'ERR_MODULE_NOT_FOUND'
}