Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Error when using getmac package #519

Closed
t16n opened this issue Sep 5, 2018 · 15 comments
Closed

Error when using getmac package #519

t16n opened this issue Sep 5, 2018 · 15 comments
Labels

Comments

@t16n
Copy link

t16n commented Sep 5, 2018

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)

@balupton
Copy link

balupton commented Sep 5, 2018

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
Copy link

balupton commented Sep 5, 2018

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)

@t16n
Copy link
Author

t16n commented Sep 5, 2018

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

@bcatalin
Copy link

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

@balupton
Copy link

balupton commented Sep 17, 2018

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
Copy link

balupton commented Dec 17, 2018

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

git clone git@github.com: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

@smxsm
Copy link

smxsm commented Apr 30, 2019

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]
....

@balupton
Copy link

balupton commented Apr 30, 2019

For what it's worth, Zeit haven't given any explicit interest in resolving this issue (be it workaround or not): vercel/ncc#236

@smxsm
Copy link

smxsm commented Apr 30, 2019

@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.

@iseedouble
Copy link

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

@balupton
Copy link

balupton commented Jul 20, 2019

@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
#519 (comment)

@mpowell90
Copy link

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

@balupton
Copy link

balupton commented Dec 6, 2019

Try with getmac v4

@github-actions
Copy link

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 github-actions bot added the Stale label Apr 13, 2021
@github-actions
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants