pkg icon indicating copy to clipboard operation
pkg copied to clipboard

Error when using getmac package

Open t16n opened this issue 8 years ago • 15 comments

Hi I am not sure why I can not get pkg to run when I use getmac as a dependency: package.json: { "name": "getmactest", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "getmac": "^1.4.6" } }

index.js: // Fetch the computer's mac address require('getmac').getMac(function(err, macAddress){ if (err) throw err console.log(macAddress) }) Error log after sudo pkg index.js

Error: There are no suitable editions for this environment: opts: { cwd: '/snapshot/getmactest/node_modules/errlop', package: 'errlop' } editions: [ { description: 'Source + ESNext + Require', entry: 'index.js', directory: 'source', syntaxes: [ 'javascript', 'esnext', 'require' ] }, { description: 'Babel Compiled + ES2015 + Require', entry: 'index.js', directory: 'es2015', syntaxes: [ 'javascript', 'es2015', 'require' ] } ] failures: [ Error: Failed to load the edition due to a load error: edition: { description: 'Source + ESNext + Require', entry: 'index.js', directory: 'source', syntaxes: [ 'javascript', 'esnext', 'require' ] } error: 'Error: Cannot find module '/snapshot/getmactest/node_modules/errlop/source/index.js'\n at Function.Module._resolveFilename (module.js:545:15)\n at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1278:46)\n at Function.Module._load (module.js:472:25)\n at Module.require (module.js:594:17)\n at Module.require (pkg/prelude/bootstrap.js:1157:31)\n at Object.require (internal/module.js:11:18)\n at requireEdition (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:138:15)\n at requireEditions (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:179:11)\n at Object.requirePackage (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:207:9)\n at Object. (/snapshot/getmactest/node_modules/errlop/index.js:3:38)' at new DetailedError (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:28:109) at requireEdition (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:141:26) at requireEditions (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:179:11) at Object.requirePackage (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:207:9) at Object. (/snapshot/getmactest/node_modules/errlop/index.js:3:38) at Module._compile (pkg/prelude/bootstrap.js:1252:22) at Object.Module._extensions..js (module.js:661:10) at Module.load (module.js:563:32) at tryModuleLoad (module.js:503:12) at Function.Module._load (module.js:495:3), Error: Failed to load the edition due to a load error: edition: { description: 'Babel Compiled + ES2015 + Require', entry: 'index.js', directory: 'es2015', syntaxes: [ 'javascript', 'es2015', 'require' ] } error: 'Error: Cannot find module '/snapshot/getmactest/node_modules/errlop/es2015/index.js'\n at Function.Module._resolveFilename (module.js:545:15)\n at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1278:46)\n at Function.Module._load (module.js:472:25)\n at Module.require (module.js:594:17)\n at Module.require (pkg/prelude/bootstrap.js:1157:31)\n at Object.require (internal/module.js:11:18)\n at requireEdition (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:138:15)\n at requireEditions (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:179:11)\n at Object.requirePackage (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:207:9)\n at Object. (/snapshot/getmactest/node_modules/errlop/index.js:3:38)' at new DetailedError (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:28:109) at requireEdition (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:141:26) at requireEditions (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:179:11) at Object.requirePackage (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:207:9) at Object. (/snapshot/getmactest/node_modules/errlop/index.js:3:38) at Module._compile (pkg/prelude/bootstrap.js:1252:22) at Object.Module._extensions..js (module.js:661:10) at Module.load (module.js:563:32) at tryModuleLoad (module.js:503:12) at Function.Module._load (module.js:495:3) ] at new DetailedError (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:28:109) at requireEditions (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:186:8) at Object.requirePackage (/snapshot/getmactest/node_modules/errlop/node_modules/editions/es2015/index.js:207:9) at Object. (/snapshot/getmactest/node_modules/errlop/index.js:3:38) at Module._compile (pkg/prelude/bootstrap.js:1252:22) at Object.Module._extensions..js (module.js:661:10) at Module.load (module.js:563:32) at tryModuleLoad (module.js:503:12) at Function.Module._load (module.js:495:3) at Module.require (module.js:594:17)

t16n avatar Sep 05 '18 12:09 t16n

Can you upload your sample test case to a git repo somewhere and include the package.lock.json file in it. I’ll start debugging it in 12 hours, as bed time here.

balupton avatar Sep 05 '18 12:09 balupton

So getmac uses editions, and when editions tries to load (editions uses errlop), it encounters and error with errlop, which uses editions, so editions doesn’t even load.

It seems this is due to pkg not supporting editions. Either pkg adds support for editions, or we update the hundreds of packages that use editions to supprt pkg, which I guess would be including this gardbage everywhere:

"pkg": {
  "scripts": ["edition*/**/*.js", “source/**/*.js”]
}

It would be much better if pkg followed the type annotation in the index.js files that do the editions magic, and bundles what the type annotation suggests. This is what typescript does. That convention is already being followed by new packages using editions, and will make its way to all the others soon enough.

'use strict'
/** @type {typeof import("./source/index.js") } */
module.exports = require('editions').requirePackage(__dirname, require)

balupton avatar Sep 05 '18 13:09 balupton

You can find the example here: https://github.com/t16n/getmactest

To replicate:

  1. clone
  2. run npm install
  3. run node index.js should return your mac address
  4. install pkg and run
  5. pkg index.js
  6. execute binary for example: ./index-linux
  7. get the error mentioned above

t16n avatar Sep 05 '18 18:09 t16n

Also is not working with nexe. After I've commented the getmac was working again.

bcatalin avatar Sep 17 '18 11:09 bcatalin

The problem is pkg doesn’t include the necessary files, as it doesn’t support dynamic values for require statements. The pkg authors will need to support editions or support @type import comments. The @type import comments is how other tooling like TypeScript workaround dynamic requires.

balupton avatar Sep 17 '18 22:09 balupton

With the release of ncc, I wanted to see if anything has changed:

git clone [email protected]:t16n/getmactest.git
cd getmactest
npm i
node ./index.js
ncc build index.js  -o dist
node ./dist/index.js
pkg index.js -t node10-macos
./index

So ncc works fine, however pkg gives the known editions failure.

This still means that:

  1. pkg needs to add support for editions
  2. or; pkg needs to expose a package.json field for a custom entry that it will use, that package authors can utilise
  3. or; pkg needs to do whatever ncc does

The correct title of this issue should be called pkg does not support editioned packages, as the issue will affect any package that is making use of editions

balupton avatar Dec 17 '18 13:12 balupton

I can confirm this, pkg still doesn't work with packages using "editions", e.g. https://www.npmjs.com/package/envfile ... gives errors like

Error: There were no suitable editions for package [/snapshot/movies2/node_modules/envfile/package.json]
....

smxsm avatar Apr 30 '19 05:04 smxsm

For what it's worth, Zeit haven't given any explicit interest in resolving this issue (be it workaround or not): https://github.com/zeit/ncc/issues/236

balupton avatar Apr 30 '19 06:04 balupton

@balupton hm, that's sad :( Since only one package was affected in my case, I switched from "envfile" to "js-yaml" and converted my .env file to a yaml file ... but in general the packages using "editions" seem to be quite popular, so it would be really cool to be able to use them with pkg/ncc.

smxsm avatar Apr 30 '19 07:04 smxsm

@balupton is there any workaround for this error : Error: There were no suitable editions for package [/snapshot/movies2/node_modules/envfile/package.json] ?

iseedouble avatar Jul 19 '19 20:07 iseedouble

@iseedouble just got to wait for zeit, onus is on them, however they don't seem to care, so I've been gradually moving away from their ecosystem over the last year, details a few comments back https://github.com/zeit/pkg/issues/519#issuecomment-447855297

balupton avatar Jul 20 '19 05:07 balupton

I've run into this while cross-compiling for armv7 - has anyone found a workaround?

mpowell90 avatar Aug 20 '19 13:08 mpowell90

Try with getmac v4

balupton avatar Dec 06 '19 20:12 balupton

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] avatar Apr 13 '21 00:04 github-actions[bot]

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.

github-actions[bot] avatar Apr 19 '21 00:04 github-actions[bot]