Since the package is now ESM-only, we need to import bencode. However currently the docs incorrectly state the way to use it is:
var bencode = require( 'bencode' )
What version of this package are you using?
v3.0.0
What operating system, Node.js, and npm version?
OS: Arch Linux x86_64, Kernel: 6.0.10-arch2-1
Node: v16.10.0
NPM: 7.24.0
What happened?
file:///tmp/bcode/main.js:1
const bencode = require('bencode');
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/tmp/bcode/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///tmp/bcode/main.js:1:17
at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
at async Loader.import (node:internal/modules/esm/loader:178:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5)
at async handleMainPromise (node:internal/modules/run_main:63:12)
What did you expect to happen?
Import would work
Are you willing to submit a pull request to fix this bug?
Since the package is now ESM-only, we need to
import
bencode. However currently the docs incorrectly state the way to use it is:What version of this package are you using?
v3.0.0
What operating system, Node.js, and npm version?
OS: Arch Linux x86_64, Kernel: 6.0.10-arch2-1 Node: v16.10.0 NPM: 7.24.0
What happened?
What did you expect to happen?
Import would work
Are you willing to submit a pull request to fix this bug?
Yes