Description
Bug Report
π Search Terms
require not used
π Version & Regression Information
- I was unable to test this on prior versions because not needed
β― Playground Link
Playground link with relevant code
π» Code
import module from 'module';
/**
* Wrapper that exposes the CJS version of the bindings
* to get imported in ESM
* @deprecated use import('node-cblite/cblite.js)
*/
const require = module.createRequire(import.meta.url);
const cblite = require('./binding.cjs');
export { cblite };
π Actual behavior
src/native/binding.js:7:7 - error TS6133: 'require' is declared but its value is never read.
7 const require = module.createRequire(import.meta.url);
π Expected behavior
require is used it can be fixed via renaming it to Require with CamelCase
i guess this is part of the nodenext resolve and that js does not preserve the require call and will translate it even when it does not come from the nativ require so require is some how now a reserved word in .js files which is not expected! as they are modules defined by package.json type module
this is even more evil when you target other environments that also got a own require implementation no matter which one require-js or the graaljs engine the deno engine anything running on raw v8 that implements require,
require is a relativ common function name in many environments and does not match the NodeJS.Require type
Solution
When moduleResolution: nodenext + target: ESNext that also implicit sets preserve require in all current nodejs versions and environments require should stay require because it only exists for backward compat and is most time always a shim as we produce nodeNext from ESNext for ESNext
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "nodenext",
and yes there are 2 package.json near that one in the project dir and one even in the outer ../
both similar whole content
{ "type": "module" }