Skip to content

Instantly share code, notes, and snippets.

@johnsonjo4531
Last active September 12, 2019 01:03
Show Gist options
  • Save johnsonjo4531/cbdace0097f9a658fd7c3ff439f5111e to your computer and use it in GitHub Desktop.
Save johnsonjo4531/cbdace0097f9a658fd7c3ff439f5111e to your computer and use it in GitHub Desktop.
An example of a failed pkg run
node_modules
index*
!index.js
node_modules
index*
!index.js

Failed PKG output

I was getting the following error when running pkg on my project:

pkg/prelude/bootstrap.js:1185
      throw error;
      ^

Error: No native build was found for platform=linux arch=x64 runtime=node abi=64 uv=1 libc=musl
    at Function.load.path (/snapshot/app/node_modules/node-gyp-build/index.js:56:9)
    at load (/snapshot/app/node_modules/node-gyp-build/index.js:20:30)
    at Object.<anonymous> (/snapshot/app/node_modules/sodium-native/index.js:1:101)
    at Module._compile (pkg/prelude/bootstrap.js:1261:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:710:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:635:17)
    at Module.require (pkg/prelude/bootstrap.js:1166:31)

This error seems to be the same as this issue vercel/pkg#705. I was able to narrow the error down to the following minimal project whose files are here.

Reproducing the error

First git clone or download the zip of this gist. Then you can either reproduce the error on your machine (I am using and reproducing the error on macOS mojave 10.14.6) or you can reproduce the error on docker node10-alpine image with the following image file. I will include steps for both.

Reproducing on MacOS (or possibly your machine)

  • If you haven't already, git clone or download the zip of this gist and enter the gist directory
  • Run yarn install
  • Run yarn build
  • Open the application from finder, here the following error should appear in the terminal:
pkg/prelude/bootstrap.js:1185
      throw error;
      ^

Error: No native build was found for platform=darwin arch=x64 runtime=node abi=64 uv=1 libc=glibc
    at Function.load.path (/snapshot/test/node_modules/node-gyp-build/index.js:56:9)
    at load (/snapshot/test/node_modules/node-gyp-build/index.js:20:30)
    at Object.<anonymous> (/snapshot/test/node_modules/sodium-native/index.js:1:101)
    at Module._compile (pkg/prelude/bootstrap.js:1261:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:710:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:635:17)
    at Module.require (pkg/prelude/bootstrap.js:1166:31)
logout
Saving session...completed.

[Process completed]

Reproducing from node10-alpine on Docker

  • enter the directory
  • run yarn docker:build (it could take a while)
  • run yarn docker:run
  • the following error output should appear:
yarn run v1.17.3
$ docker container run -t failed-pkg
pkg/prelude/bootstrap.js:1185
      throw error;
      ^

Error: No native build was found for platform=linux arch=x64 runtime=node abi=64 uv=1 libc=musl
    at Function.load.path (/snapshot/app/node_modules/node-gyp-build/index.js:56:9)
    at load (/snapshot/app/node_modules/node-gyp-build/index.js:20:30)
    at Object.<anonymous> (/snapshot/app/node_modules/sodium-native/index.js:1:101)
    at Module._compile (pkg/prelude/bootstrap.js:1261:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:710:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:635:17)
    at Module.require (pkg/prelude/bootstrap.js:1166:31)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Verifying the file runs normally

This is just to show the file can be run normally

On your platform (MacOS tested)

  • enter the directory
  • yarn install
  • yarn start
  • should then output Authenticated.

On Docker

  • enter the directory
  • yarn docker:build
  • yarn docker:sh
  • (You should now be in the node10-alpine docker container shell)
  • yarn start
  • should then output Authenticated.
  • type exit to exit the node10-alpine image shell
FROM node:10-alpine
WORKDIR /usr/src/app
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
RUN apk add --no-cache --virtual .gyp \
build-base \
automake \
autoconf \
libtool \
libsodium \
python \
make \
g++ \
&& npm install -g yarn
COPY package.json ./
COPY yarn.lock ./
RUN npm install -g pkg
RUN yarn install --production=false \
&& apk del .gyp
COPY . .
RUN pkg -t node10-alpine-x64 index.js
CMD ["./index"]
// OTHER THAN THIS COMMENT THIS IS AN EXACT COPY OF SECURE-PASSWORD's NPM PAGE EXAMPLE
// LICENSE ISC
var securePassword = require('secure-password')
// Initialise our password policy
var pwd = securePassword()
var userPassword = Buffer.from('my secret password')
// Register user
pwd.hash(userPassword, function (err, hash) {
if (err) throw err
// Save hash somewhere
pwd.verify(userPassword, hash, function (err, result) {
if (err) throw err
switch (result) {
case securePassword.INVALID_UNRECOGNIZED_HASH:
return console.error('This hash was not made with secure-password. Attempt legacy algorithm')
case securePassword.INVALID:
return console.log('Invalid password')
case securePassword.VALID:
return console.log('Authenticated')
case securePassword.VALID_NEEDS_REHASH:
console.log('Yay you made it, wait for us to improve your safety')
pwd.hash(userPassword, function (err, improvedHash) {
if (err) console.error('You are authenticated, but we could not improve your safety this time around')
// Save improvedHash somewhere
})
break
}
})
})
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"secure-password": "^3.1.0"
},
"scripts": {
"start": "node index.js",
"build": "pkg index.js",
"docker:build": "docker build -t failed-pkg .",
"docker:run": "docker container run -t failed-pkg",
"docker:sh": "docker container run -it failed-pkg sh"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
ini@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
nan@^2.14.0:
version "2.14.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==
nanoassert@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/nanoassert/-/nanoassert-1.1.0.tgz#4f3152e09540fde28c76f44b19bbcd1d5a42478d"
integrity sha1-TzFS4JVA/eKMdvRLGbvNHVpCR40=
node-gyp-build@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.1.1.tgz#d7270b5d86717068d114cc57fff352f96d745feb"
integrity sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ==
secure-password@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/secure-password/-/secure-password-3.1.0.tgz#57abe12c1b3db2107b048ee12a724a0d3023757e"
integrity sha512-9t7OQXKfCl4WhX+A+2O2H0g0GpTh6499KOyy2an2paD3rM9JAolAqWiQvz38CngvTqFHXow4OoamIX6YjC2JAw==
dependencies:
nanoassert "^1.0.0"
sodium-native "^2.2.1"
sodium-native@^2.2.1:
version "2.4.6"
resolved "https://registry.yarnpkg.com/sodium-native/-/sodium-native-2.4.6.tgz#8a8173095e8cf4f997de393a2ba106c34870cac2"
integrity sha512-Ro9lhTjot8M01nwKLXiqLSmjR7B8o+Wg4HmJUjEShw/q6XPlNMzjPkA1VJKaMH8SO8fJ/sggAKVwreTaFszS2Q==
dependencies:
ini "^1.3.5"
nan "^2.14.0"
node-gyp-build "^4.1.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment