10gen / realm-cli

MongoDB Realm CLI
Apache License 2.0
6 stars 23 forks source link

Error when executing `realm-cli` #68

Open DeveloperRic opened 3 years ago

DeveloperRic commented 3 years ago

Hi, I'm looking to use this CLI to automatically manage my Realm apps but I can't seem to get the command to run during testing.

When I run realm-cli with any option (login, --yes, 12345, ...) or even without an option, the command fails with this stacktrace:

This stacktrace is from a global install

$ npm i -g mongodb-realm-cli
$ realm-cli
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: spawn C:\Users\Victor\AppData\Roaming\npm\node_modules\mongodb-realm-cli\realm-cli.exe ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

This stacktrace is from a local install

$ npm i mongodb-realm-cli
$ npx realm-cli
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: spawn C:\Users\Victor\Desktop\Code\...\node_modules\mongodb-realm-cli\realm-cli.exe ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Why is this happening?

DeveloperRic commented 3 years ago

If this helps, I'm running:

Windows 10 Pro Version 1809 Git Bash from git version 2.17.1.windows.2 Nodejs v10.23.3 NPM 6.14.10

The version of realm-cli I'm running is:

mongodb-realm-cli@1.2.0 | Apache-2.0 | deps: 1 | versions: 3
The MongoDB Realm Command Line Interface
https://github.com/10gen/realm-cli#readme

keywords: mongodb, realm

bin: realm-cli, transpiler

dist
.tarball: https://registry.npmjs.org/mongodb-realm-cli/-/mongodb-realm-cli-1.2.0.tgz
.shasum: 8e4a0536ca7a94b497ae0ef9c64a258652c68bc2
.integrity: sha512-lba8wr9hrlXR7xMYv2FDICSPY+TkWkrbA4TnyxZhfmIUxTwnb+ClaR4k6KNtEB1W51j0Qbsd/1tRhLuxmvTLKQ==
.unpackedSize: 45.6 MB

dependencies:
request: ^2.88.0 

maintainers:
- unicodesnowman <caplingerc@gmail.com>

dist-tags:
latest: 1.2.0  

published 3 months ago by unicodesnowman <caplingerc@gmail.com>
DeveloperRic commented 3 years ago

Update: Manually downloading the executable works on my dev machine. However, I'd still like to use a versioned copy of the CLI.

$ lib/realm-cli.exe
Usage: realm-cli.exe [--version] [--help] <command> [<args>]

Available commands are:
    diff       View the changes you would make to the current app without importing the changes.
    export     Export a realm application to a local directory.
    import     Import and deploy a realm application from a local directory.
    login      Log in using an Atlas Programmatic API Key
    logout     Deauthenticate as an administrator.
    secrets    Add or remove secrets for your Realm App.
    whoami     Display Current User Info
UnicodeSnowman commented 3 years ago

Hi @DeveloperRic I'll have a look at this today and see if I can reproduce. I haven't seen this happen before but I'll do some sleuthing.

UnicodeSnowman commented 3 years ago

@DeveloperRic I'm setting up a Windows environment now to try to repro this, but my guess is that there's something problematic here with the wrapper script that invokes the actual realm-cli binary (note, the actual CLI is a binary/executable, which just use npm for easy distribution since many users are familiar with it. there's a simple wrapper.js script that actually calls the CLI and passes args). can you try calling the binary directly? I'm not sure where global packages are installed on Windows, but for me, the actual binary is located at /usr/local/lib/node_modules/mongodb-realm-cli/realm-cli (in your case it should be realm-cli.exe). note that this is also the location of the wrapper.js script.

I'll keep you updated as I try to repro this on my end.

DeveloperRic commented 3 years ago

For me, the global executable lives at /c/Users/Victor/AppData/Roaming/npm/realm-cli, running it with the full path (without npx) gives the same stacktrace as in my original comment. Btw the Windows executable at https://realm.mongodb.com/groups/.../app/.../deploy/importexport works as expected, it's just the executable bundled with npm that gives the error.

UnicodeSnowman commented 3 years ago

/c/Users/Victor/AppData/Roaming/npm/realm-cli, running it with the full path (without npx) gives the same stacktrace as in my original comment.

hmm it throws the same JS error (referring to events.js:174, etc.) when you run it directly at that path? that looks like it's still running the wrapper script via a bash script (looking myself, /c/Users/<USER>/AppData/Roaming/npm/realm-cli appears to be a bash script that calls wrapper.js) rather than the actual executable itself.

can you call the executable that it's referencing directly? should be at /c/Users/Victor/AppData/Roaming/npm/node_modules/mongodb-realm-cli/realm-cli.exe. if that works correctly (I have a feeling it will), can you try executing the wrapper.js script directly (instead of calling it through the bash script) via /c/Users/Victor/AppData/Roaming/npm/node_modules/mongodb-realm-cli/wrapper.js. curious if this is an issue with that wrapper script, or with the bash script that calls the wrapper.

I just tried this myself on Windows 10 (with the same node version, via git bash, etc.) and I'm not seeing any issues.

DeveloperRic commented 3 years ago

For some reason I don't have a /c/Users/Victor/AppData/Roaming/npm/node_modules directory, all global 'executables' are in /c/Users/Victor/AppData/Roaming/npm. The local install also doesn't contain a realm-cli.exe file:

$ ls -l /c/Users/Victor/Desktop/Code/.../node_modules/mongodb-realm-cli
total 44526
-rw-r--r-- 1 Victor 197609     1219 Oct 26  1985 go.mod
-rw-r--r-- 1 Victor 197609    25405 Oct 26  1985 go.sum
-rw-r--r-- 1 Victor 197609     3734 Oct 26  1985 install.js
-rw-r--r-- 1 Victor 197609    10273 Oct 26  1985 LICENSE
-rw-r--r-- 1 Victor 197609     2066 Feb 18 20:15 package.json
-rw-r--r-- 1 Victor 197609     2277 Oct 26  1985 README.md
-rw-r--r-- 1 Victor 197609     2739 Oct 26  1985 Session.vim
-rwxr-xr-x 1 Victor 197609     2973 Oct 26  1985 testInstall.js
-rw-r--r-- 1 Victor 197609 45521277 Oct 26  1985 transpiler
-rw-r--r-- 1 Victor 197609      123 Oct 26  1985 version.json
-rwxr-xr-x 1 Victor 197609      641 Oct 26  1985 wrapper.js
-rwxr-xr-x 1 Victor 197609      643 Oct 26  1985 wrapper-transpiler.js

Looking in mongodb-realm-cli/package.json, I believe npm is generating the realm-cli executable at install: (yellow are files in /c/Users/Victor/AppData/Roaming/npm) image

Also, unfortunately, same error with wrapper.js

$ /c/Users/Victor/Desktop/Code/.../node_modules/mongodb-realm-cli/wrapper.js
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: spawn C:\Users\Victor\Desktop\Code\...\node_modules\mongodb-realm-cli\realm-cli.exe ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Problem

Turns out the problem was on my end (sort of). I have the npm config ignore-scripts set to true for security reasons, so this blocked mongodb-realm-cli/install.js from running and so the realm-cli executable was never downloaded.

Caveats:

It might be worth bundling the executable in the installation/an executable that will run install if realm-cli.exe doesn't exist so people like me don't have to turn off ignore-scripts 🙂

UnicodeSnowman commented 3 years ago

ah thanks for the update. yeah, I agree, there's likely a better/alternate way we can handle this type of case. I'll think on this and try to figure something out over the new few days. Additionally, I want to make sure we're surfacing the semver release version for CLIs downloaded directly via the UI.