I am using Rails 6 in a VirtualBox virtual machine through Vagrant.
Vagrant mounts shared folder (with project) from the host system (Windows) to the Ubuntu 20LTS virtual machine.
And it happens that in my case symlinks don't work in this shared folder.
(There is a key with which the symlinks should work, but it did not happen)
And here's the problem.
When yarn installs packages in node_modules it creates symlinks as well.
And then I get an error because the symlinks don't work:
error An unexpected error occurred: "EPROTO: protocol error, symlink
Ok, I thought that folder node_modules can be moved outside of the project and the shared folder in the virtual machine, where the symlinks will work.
And indeed, you can create a .yarnrc
file in the project folder with the contents:
"--modules-folder" "/home/user/custom_path/node_modules"
Now running yarn add
or rake webpacker:install
will install all packages in the specified directory.
It would seem that the problem is solved.
However, Webpacker doesn't know anything about .yarnrc
and keeps looking for it in the root of the project.
And if for example you call rake webpacker:info
:
Ruby: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
Rails: 6.1.4.1
Webpacker: 5.4.3
Node: v16.13.0
Yarn: 1.22.17
@rails/webpacker:
project@0.1.0 /home/vagrant/data/shared/project
└── (empty)
Is bin/webpack present?: true
Is bin/webpack-dev-server present?: true
Is bin/yarn present?: true
empty
- It doesn't see those @rails/webpacker.
However, its in custom node_modules.
I tried writing in config/webpacker.yml
additional_paths: ["/home/user/custom_path/node_modules"]
However, this doesn't have the desired effect.
And at the compile stage I get an error:
Error: Cannot find module '@rails/webpacker'
package.json
is in the root of the project and this and other packages are prescribed there.
Question: how to correctly specify the path to node_modules to make everything work?
Yes it's all in the context of development/test environment for rails.