envkey / envkey-node

EnvKey's official Node.js client library
https://www.envkey.com
MIT License
49 stars 9 forks source link

Error deploying to now.sh lambda #18

Closed shamoons closed 5 years ago

shamoons commented 5 years ago
2019-08-14T22:13:21.527Z    undefined   ERROR   TypeError: Cannot read property 'toString' of null
    at fetch (/var/task/node_modules/envkey/loader.js:215:30)
    at Object.load (/var/task/node_modules/envkey/loader.js:91:29)
    at Object.<anonymous> (/var/task/node_modules/envkey/index.js:1:41)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)

That's the error I get.

shamoons commented 5 years ago

Very strange indeed. I tried running this directly on the lamba and it worked:

    const key = process.env.ENVKEY
    var ext = "",
        filePath = path.join(__dirname, "node_modules", "envkey", "ext", ["envkey-fetch", ENVKEY_FETCH_VERSION, platformPart, 'amd64'].join("_"), ("envkey-fetch" + ext)),
        execArgs = [key, "--client-name", "envkey-node", "--client-version", "1.2.6"]

    var resp = execFileSync(filePath, execArgs).toString()

So I'm not sure what the error is

shamoons commented 5 years ago

cc @danenania

danenania commented 5 years ago

Hmm, definitely strange—looking into this.

On Wed, Aug 14, 2019 at 5:51 PM Shamoon Siddiqui notifications@github.com wrote:

cc @danenania https://github.com/danenania

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/envkey/envkey-node/issues/18?email_source=notifications&email_token=AAEFERUR5R6ATKWZF7XUMWLQESSARA5CNFSM4ILZOT52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4KQVOY#issuecomment-521472699, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEFERT66CBYCSYUJY774H3QESSARANCNFSM4ILZOT5Q .

danenania commented 5 years ago

It looks like error is not being handled and display properly... e.stderr is null in console.error(e.stderr.toString())

I'm pushing a fix for that right now so that we can see what the underlying error is.

danenania commented 5 years ago

Ok, 1.2.7 is now released with the error handling fixed. Can you post the error message with the new version when you get a chance?

shamoons commented 5 years ago

Logs are better, but still error:

START RequestId: 0e0f9e4f-fc9c-4365-8556-3e909d4e8699 Version: $LATEST
2019-08-15T12:04:04.970Z    undefined   ERROR   Error: spawnSync /var/task/node_modules/envkey/ext/envkey-fetch_1.2.5_linux_amd64/envkey-fetch ENOENT
    at Object.spawnSync (internal/child_process.js:1002:20)
    at spawnSync (child_process.js:614:24)
    at execFileSync (child_process.js:642:13)
    at fetch (/var/task/node_modules/envkey/loader.js:201:17)
    at Object.load (/var/task/node_modules/envkey/loader.js:91:29)
    at Object.<anonymous> (/var/task/node_modules/envkey/index.js:1:41)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-08-15T12:04:04.974Z    undefined   ERROR   { Error: spawnSync /var/task/node_modules/envkey/ext/envkey-fetch_1.2.5_linux_amd64/envkey-fetch ENOENT
    at Object.spawnSync (internal/child_process.js:1002:20)
    at spawnSync (child_process.js:614:24)
    at execFileSync (child_process.js:642:13)
    at fetch (/var/task/node_modules/envkey/loader.js:201:17)
    at Object.load (/var/task/node_modules/envkey/loader.js:91:29)
    at Object.<anonymous> (/var/task/node_modules/envkey/index.js:1:41)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall:
   'spawnSync /var/task/node_modules/envkey/ext/envkey-fetch_1.2.5_linux_amd64/envkey-fetch',
  path:
   '/var/task/node_modules/envkey/ext/envkey-fetch_1.2.5_linux_amd64/envkey-fetch',
  spawnargs:
   [ 'aAgSa12RWyGRsgENG7HF-5PQoFtZC2sZnw5WJ',
     '',
     '--client-name',
     'envkey-node',
     '--client-version',
     '1.2.7' ],
  error: [Circular],
  status: null,
  signal: null,
  output: null,
  pid: 19,
  stdout: null,
  stderr: null }
END RequestId: 0e0f9e4f-fc9c-4365-8556-3e909d4e8699
REPORT RequestId: 0e0f9e4f-fc9c-4365-8556-3e909d4e8699  
Duration: 155.14 ms  Billed Duration: 200 ms   Memory Size: 3008 MB  Max Memory Used: 28 MB 
RequestId: 0e0f9e4f-fc9c-4365-8556-3e909d4e8699 Error: Runtime exited with error: exit status 1
Runtime.ExitError
shamoons commented 5 years ago

Oops - looks like I need to revoke that envkey now. (In case any clever hackers were attempting to see my secrets). But yeah, still no dice

shamoons commented 5 years ago

I figured it out. https://spectrum.chat/zeit/now/using-exec-and-node-module-path-directory-in-now-node~143259bd-7071-441f-b95d-a4733e2ba045

Basically, ncc strips out everything and removes node_modules. I guess for now, I can use envkey-node as a submodule in my repo

shamoons commented 5 years ago

Actually, I'm also using https://github.com/joshwnj/ffprobe-static and this executes fine within now.sh. So I'm not sure why those binaries aren't being stripped out?

shamoons commented 5 years ago

Got it to work (for now). Work around was to:

  1. Fork and reduce size since now.sh lambdas can be a max of 50mb (https://github.com/shamoons/envkey-node/tree/linux64)
  2. In my now.json, I have:
    "builds": [{
        "src": "index.js",
        "use": "@now/node",
        "config": {
            "bundle": false,
            "includeFiles": [
                "node_modules/envkey/**"
            ]
        }
    }],
danenania commented 5 years ago

Ah, I was thinking that module size might be the culprit, but was thrown off by the fact that your var resp = execFileSync(filePath, execArgs).toString() seemed to work. And yes, forking and removing unneeded binaries is the recommendation for dealing with that until platform-specific module loading gets done (it's on the roadmap, but so are lots of other things 😬).