I know i read the documentation but i cannot figure out how to comiple the .node files into the executables and place in the same directory.
https://github.com/zeit/pkg#native-addons
Error: Cannot find module 'D:\snapshot\server\node_modules\bcrypt\lib\binding\bcrypt_lib.node'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1252:46)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at Module.require (pkg/prelude/bootstrap.js:1136:31)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:\snapshot\server\node_modules\bcrypt\bcrypt.js:6:16)
at Module._compile (pkg/prelude/bootstrap.js:1226:22)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at Module.require (pkg/prelude/bootstrap.js:1136:31)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:\snapshot\server\class\SetupClass.js:0:0) code: 'MODULE_NOT_FOUND', pkg: true }
Same issue here! :|
Same here... problem with compiling node with bcrypt. Issue does not affect macos target, but affects linux target. So I was easily able to make it work for macos, but not for ubuntu.
I used this https://www.npmjs.com/package/bcryptjs and it worked fine with pkg.
Same issue here, even if bcryptjs works, that projects has much less reputation than bcrypt. It's important to get this working.
So I had to add this line to my Dockerfile:
RUN cp node_modules/bcrypt/lib/binding/bcrypt_lib.node .
And it seems to work now.
My complete Dockerfile:
FROM node:8-alpine as base
# Needed for bcrypt
RUN apk add --no-cache make gcc g++ python
# Get pkg packages
RUN yarn global add pkg pkg-fetch
ENV NODE node8
ENV PLATFORM alpine
ENV ARCH x64
RUN pkg-fetch ${NODE} ${PLATFORM} ${ARCH}
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install dependencies
COPY package*.json ./
COPY yarn.lock ./
RUN yarn --production
# Needed in order for bcrypt to work on alpine
# @see https://github.com/kelektiv/node.bcrypt.js/issues/528
RUN npm rebuild bcrypt --build-from-source
# Bundle app source
COPY . .
RUN cp node_modules/bcrypt/lib/binding/bcrypt_lib.node .
RUN ls -la .
# Build assets
RUN pkg package.json --targets ${NODE}-${PLATFORM}-${ARCH} --output server-start
# --- Release with Alpine ----
FROM node:8-alpine AS release
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY --from=base /usr/src/app/server-start ./
COPY --from=base /usr/src/app/*.node ./
# Exports
USER node
EXPOSE 3000
CMD [ "./server-start" ]
I think the key is to have the .node file in the same directory as the executable that pkg generated
Same issue here, still not fixed
Most helpful comment
So I had to add this line to my Dockerfile:
And it seems to work now.
My complete Dockerfile:
I think the key is to have the
.nodefile in the same directory as the executable that pkg generated