You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Running in ESM (*.mjs) returns "ERROR : use init before" #186
OpenEmbedded / Yocto / Linux kernel 5.4.88 running on i.MX6X with ath6k and bcm43236b drivers
Version of node-wifi
2.0.16
Steps to Reproduce
app.mjs
import*aswififrom'node-wifi'exportclassApp{staticasyncstart(){console.log(process.platform)wifi.init({debug: true,iface: null// network interface, choose a random wifi interface if set to null})wifi.scan().then(networks=>{console.log(networks)}).catch(e=>{console.log(e)})}}App.start()
$ node app.mjs
linux
ERROR : use init before
Solutions
maybe related to
exports.scan=()=>{thrownewError('ERROR : use init before');};
$ node app.mjs
darwin
(node:12343) UnhandledPromiseRejectionWarning: Error: ERROR : use init before
at Module.exports.scan (/xxx/node_modules/node-wifi/src/wifi.js:77:9)
at Function.start (file:///xxx/app.mjs:14:14)
at file:///xxx/app.mjs:24:5
at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12343) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12343) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
When using type: "module", importing a CommonJS such as node-wifi requires special attention. node-wifi does not natively support ESM, so you must use the createRequire method of Node.js.
Activity
SunboX commentedon Jan 23, 2023
Running it on macOS:
zN3utr4l commentedon Nov 21, 2024
When using type: "module", importing a CommonJS such as node-wifi requires special attention. node-wifi does not natively support ESM, so you must use the createRequire method of Node.js.