Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm install largely does not work within Vagrant #320

Open
orblivion opened this issue Jan 18, 2022 · 0 comments
Open

npm install largely does not work within Vagrant #320

orblivion opened this issue Jan 18, 2022 · 0 comments

Comments

@orblivion
Copy link

orblivion commented Jan 18, 2022

When I try to build an app that uses npm install with vagrant-spk, certain node packages have assorted errors of expected files missing during the build process. If I ssh into the VM to inspect the situation, I find that the containing directories are often not there either.

I poked around the Internet and it seems to be a known issue with VirtualBox and npm:

I'm not sure I get the complete picture of what's going on. Supposedly this is due to VirtualBox disabling symlinks for synced folders for security reasons. From direct observation I can ssh into my VM and create a symlink, so I'm not sure exactly what's going on. But my npm is in fact failing.

Proposed Workarounds

Turn symlinks back on with a setting

You can turn the symlinks back on with a setting if you trust the guest VM. I tried it once and it didn't work. I likely did it wrong.

Bind Mount (worked for me)

You can apparently work around this with a bind mount:

Now, I'm not sure if I'm getting this suggestion right, but it worked for me in the following way:

  • In setup.sh:
    • create /opt/build
  • In build.sh:
    • copy /opt/app to /opt/build/app
    • sudo mount --bind /opt/build/app /opt/app
      • at this point /apt/app is not synced to your host, but npm will build thinking it's sitting in /opt/app.
    • do build as normal within /opt/app
      • this of course actually builds in /opt/build/app, but if your generated files ever include an absolute path (as npm packages have) they will show up as /opt/app.
    • sudo umount /opt/app
    • copy node_modules and other generated directories from /opt/build/app to their respective places in /opt/app
      • Now the built node modules are inside the synced folder, and should show up in your host

At this point it will run. If there's a problem with symlinks, I'm not sure why it does, given that it can't build. I even tried comparing the node_modules directories in /opt/app and /opt/build/app/ and they're the same.

Other

There are others. One was to use NFS to sync them, not sure how secure that is in this context.

Assorted:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants