I am using Yarn workspaces for ease of development in my monorepo.
When I run the assets:precompile task from my rails project root I am getting the following:
"/webpack_runner.rb:11:in `exec': No such file or directory - /.../node_modules/.bin/webpack (Errno::ENOENT)"
This is obvious since webpacker (WebpackRunner more specifically) assumes that yarn has installed webpack and webpack-dev-server into the local node_modules folder cmd = [ "#{@node_modules_path}/.bin/webpack", "--config", @webpack_config ] + @argv.
Should Yarn workspaces be symlinking local node_modules/.bin to the top level node_modules/.bin or should webpacker be catering for hoisted binaries?
This is the only reason we still use npm, they handle bins a bit different. :shipit:
I was able to work around this by using the "nohoist" config for yarn workspaces. I added this to the Rails package.json:
"workspaces": {
"nohoist": [
"**/@rails/**"
]
},
This forces yarn to not install @rails/* packages (including @rails/webpacker) in the workspace parent but locally. This, then drops the webpack file in .bin that webpacker sees.
I was able to work around this by using the "nohoist" config for yarn workspaces. I added this to the Rails package.json:
"workspaces": { "nohoist": [ "**/@rails/**" ] },This forces yarn to not install @rails/* packages (including @rails/webpacker) in the workspace parent but locally. This, then drops the webpack file in
.binthat webpacker sees.
Solved my problem, thanks legend!
Most helpful comment
I was able to work around this by using the "nohoist" config for yarn workspaces. I added this to the Rails package.json:
This forces yarn to not install @rails/* packages (including @rails/webpacker) in the workspace parent but locally. This, then drops the webpack file in
.binthat webpacker sees.