sandstorm-io / sandstorm

Sandstorm is a self-hostable web productivity suite. It's implemented as a security-hardened web app package manager.
https://sandstorm.io
Other
6.76k stars 705 forks source link

Cannot find module "capnp" in Meteor 1.5 projects on Ubuntu VMs #3006

Open dmitry-sher opened 7 years ago

dmitry-sher commented 7 years ago

I was working with this stack:

Everything was working flawlessly until something happened in september-october, around the time sandstorm-214/215 came out. After that, no matter what, my projects were failing to run in sandstorm environment with following error on the server-side:

** Starting Mongo...
2017-11-10T11:43:06.571+0000 I STORAGE  Engine custom option: log=(prealloc=false,file_max=200KB)
about to fork child process, waiting until server is ready for connections.
forked process: 10
child process started successfully, parent exiting
** Starting Meteor...
Note: you are using a pure-JavaScript implementation of bcrypt.
While this implementation will work correctly, it is known to be
approximately three times slower than the native implementation.
In order to use the native implementation instead, run

  meteor npm install --save bcrypt

in the root directory of your application.
/programs/server/node_modules/fibers/future.js:280
                        throw(ex);
                        ^

Error: Cannot find module "capnp"
    at Object.require (/programs/server/boot.js:232:24)
    at makeInstallerOptions.fallback (packages/modules-runtime.js:641:18)
    at require (packages/modules-runtime.js:234:16)
    at meteorInstall.sandstorm.js (sandstorm.js:5:19)
    at fileEvaluate (packages/modules-runtime.js:333:9)
    at require (packages/modules-runtime.js:228:16)
    at /programs/server/app/app.js:54:1
    at /programs/server/boot.js:339:34
    at Array.forEach (native)
    at Function._.each._.forEach (/programs/server/node_modules/underscore/underscore.js:79:11)
** HTTP-BRIDGE: App server exited with status code: 1
** SANDSTORM SUPERVISOR: Starting up grain. Sandbox type: userns

I've done following:

When i create dev bundle, in deps i can see capnp.js and all relevant files.

I've nailed the problem to simplest project with 1 page and 1 server-side file. On a page it simply shows user info. On server-side we have one file that simply requires capnp, doing nothing. This app breaks on my installs. Here is sample project: https://github.com/dmitry-sher/sandstorm-test

I can recreate VM again from scratch and provide also the VM. I think this is some problem of my environment. Because one time when i was preparing the test project, it was working, until it broke. Then i did the same steps, and it didn't work.

What can I do? Is it some bug of my environment? Should i simply use some other distro for VM? What is that distro, then?

dmitry-sher commented 7 years ago

the same happened on Debian 4.9.30-2+deb9u2

kentonv commented 7 years ago

This probably happened when you updated Meteor. Unfortunately, Meteor 1.5.2.1 changed the behavior of require() such that it will no longer find the capnp module. So if you updated to 1.5.2.1 or later, it won't work anymore. :(

This affected the Sandstorm shell, too. There I solved it with this:

https://github.com/sandstorm-io/sandstorm/blob/master/shell/packages/sandstorm-capnp/capnp.js

For apps, the same thing could work, but I'm not sure if it's the best solution.

The problem is that we're trying to make capnp appear as if it were a system module, so that it doesn't need to be declared as an npm dependency. We don't want it to be an npm dependency because building the npm package would require having libcapnp installed on the system, which is complicated. We'd rather just provide a copy with meteor-spk.

dmitry-sher commented 7 years ago

Yep, i totally understand your considerations. The workaround you showed me is working for apps and, what's even more important for me, also for packages.

kentonv commented 6 years ago

BTW I think an easier workaround specifically for Sandstorm apps might be to do:

require("/node_modules/capnp.js")

This works since meteor-spk always puts the file in exactly that spot.

xet7 commented 6 years ago

@kentonv

I do have const Capnp = require('/node_modules/capnp.js'); in Wekan sandstorm.js .

How do I remove capnp related stuff? I still get the same error.

xet7 commented 6 years ago

@kentonv

I get those errors on meteor-spk 0.4.0

kentonv commented 6 years ago

@xet7 Which error do you get? Cannot find module "capnp"? But if you aren't using require("capnp") anymore, how could you possibly get that error? Or is it a different error?

xet7 commented 6 years ago

I fixed that capnp not found error this way in Wekan: https://github.com/wekan/wekan/commit/11e9811f82858a3d98036e142b0da69d867adebc