lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

node10.x bcrypt install failure #186

Closed hmmdeif closed 5 years ago

hmmdeif commented 5 years ago

Unsure if this is due to the docker image or not (not really that familiar with building linux deps). I was upgrading my layers to node10.x and bcrypt would fail installing with:

> bcrypt@3.0.6 install /var/task/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module '../'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/var/task/node_modules/node-pre-gyp/bin/node-pre-gyp:15:20)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

In the end I just installed on 8.10 and then used npm rebuild bcrypt --build-from-source so there is a workaround. It could be this is a bcrypt problem but I'm unsure where exactly the issue lies.

mhart commented 5 years ago

Can you show me the full command you're using so I can reproduce this?

hmmdeif commented 5 years ago

docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs10.x npm install bcrypt

Note that docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs8.10 npm install bcrypt works as expected, but I assume this might be because bcrypt has prebuilt binaries for 8.10.

mhart commented 5 years ago

Hmmm, this works for me:

docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs10.x npm rebuild --build-from-source 

> bcrypt@3.0.6 install /var/task/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download 
make: Entering directory `/var/task/node_modules/bcrypt/build'
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o
  SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node
  COPY Release/bcrypt_lib.node
  COPY /var/task/node_modules/bcrypt/lib/binding/bcrypt_lib.node
  TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory `/var/task/node_modules/bcrypt/build'

It might be that a bad image was pushed up or built on docker hub? Lemme check

hmmdeif commented 5 years ago

Yeah a rebuild --build-from-source works fine, it's just that initial install that fails.

mhart commented 5 years ago

That works fine for me too:

docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs10.x npm install bcrypt

> bcrypt@3.0.6 install /var/task/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download 
[bcrypt] Success: "/var/task/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is installed via remote
npm WARN saveError ENOENT: no such file or directory, open '/var/task/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/var/task/package.json'
npm WARN task No description
npm WARN task No repository field.
npm WARN task No README data
npm WARN task No license field.

+ bcrypt@3.0.6
updated 1 package and audited 431 packages in 6.796s
found 0 vulnerabilities
mhart commented 5 years ago

It might be an npm issue? Or you've got an old version of bcrypt or something? Try installing from scratch in an empty directory (with no package.json or node_modules or whatever) – it should succeed

hmmdeif commented 5 years ago

Still no luck with that either. I can't see why it would be the host env but I am running this command on windows 10. I'm not too bothered since there is the rebuild command. If you're not getting the error then that's probably good enough to make it a non-issue!

mhart commented 5 years ago

Maybe something to do with the way the directory is being mounted? Check if this works:

docker run --rm lambci/lambda:build-nodejs10.x bash -c "cd /tmp && npm install bcrypt"
mhart commented 5 years ago

(also, just double-check you've got the latest image: docker pull lambci/lambda:build-nodejs10.x)

hmmdeif commented 5 years ago

Yep, that command worked and it is the latest image.

mhart commented 5 years ago

So I don't really know much about how Docker works on Windows and how the command line is interpreted. It could be that the directory you're in isn't accessible to Docker, or the command line doesn't know how to process "$PWD", or... dunno, a million things 😬

If you figure it out, let me know.