problem using require
nishantshah977 opened this issue · comments
What version of this package are you using?
2.0.37
What operating system, Node.js, and npm version?
Android Termux, Node.js v19.9.0, npm --version
9.6.3
What happened?
const WebTorrent = require('webtorrent');
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /data/data/com.termux/files/home/node_modules/webtorrent/index.js from /data/data/com.termux/files/home/server.js not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /data/data/com.termux/files/home/node_modules/webtorrent/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at Object.<anonymous> (/data/data/com.termux/files/home/server.js:11:20) {
code: 'ERR_REQUIRE_ESM'
}
I tried changing to type:commonjs and also renaming files but it didn't fixed
What did you expect to happen?
I'm building torrent client to run ony Android device and use port forwarding. Code is okay. I also asked GPT 😂
Are you willing to submit a pull request to fix this bug?
No
webtorrent is ESM not CJS