I'm testing out setting up yarn 2 workspaces. I think I've done it the way I'm supposed to, but when I run yarn install
from the root it doesn't install any modules nor does it create the symplink to dependencies as expected. I have the following folder structure
root/
package-a/
package-b/
Each contains a package.json and each of the package folders contains an index.js. Here are the package.json files
root:
{
"name": "yarn-workspaces-poc",
"version": "1.0.0",
"license": "MIT",
"private": true,
"workspaces": [
"package-a/",
"package-b/"
]
}
package-a:
{
"name": "package-a",
"version": "1.0.0",
"type": "module",
"dependencies": {
"cross-env": "5.0.5",
"package-b": "workspace:*"
}
}
package-b:
{
"name": "package-b",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"dependencies": {
"cross-env": "5.0.5"
}
}
Here are the js files
package-a/index.js
import test from "package-b";
console.log('testing');
console.log(test());
package-b/index.js
export default function b() {
console.log("From b. You made it!");
}
The expected behavior is that when I run yarn install
from the root a node_modules folder will be created there. It should contain the cross-env package as well as a folder symlinked to package-b. However nothing gets created. Here's the output from the command:
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done in 0s 96ms
edit:
Additionally if I just run package-a to test it this is the result:
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'
}