Error when using getmac package
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)
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.
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)
You can find the example here: https://github.com/t16n/getmactest
To replicate:
- clone
- run
npm install - run
node index.jsshould return your mac address - install pkg and run
- pkg index.js
- execute binary for example: ./index-linux
- get the error mentioned above
Also is not working with nexe. After I've commented the getmac was working again.
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.
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:
- pkg needs to add support for editions
- or; pkg needs to expose a
package.jsonfield for a custom entry that it will use, that package authors can utilise - 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
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]
....
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 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.
@balupton is there any workaround for this error : Error: There were no suitable editions for package [/snapshot/movies2/node_modules/envfile/package.json] ?
@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
I've run into this while cross-compiling for armv7 - has anyone found a workaround?
Try with getmac v4
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
This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.