node-chess: node-chess cannot be imported using common-js syntax
In the README examples, the module chess is imported using require. However, this module is an ES6 module and doesn’t allow itself to be required (at least for me).
This is the error I get when trying to require the module:
var Chess = require('chess').Chess;
^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Joey\Programming\Node.js\node_modules\chess\src\main.js from C:\Users\Joey\Programming\Node.js\chess.js not supported.
Instead change the require of main.js in C:\Users\malvi\Programming\Node.js\ChessBot\chessjstest.cjs to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (C:\Users\Joey\Programming\Node.js\chessjs.js :3:13) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v17.0.
And this is the code used to generate this error:
const Chess = require('chess').Chess;
Do the examples need to be updated, or am I doing something wrong?
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (2 by maintainers)
Commits related to this issue
- addressing #84 by adding a default export and modifying the readme to refer to module import instead of Commonjs require — committed to brozeph/node-chess by brozeph 2 years ago
- Merge pull request #85 from brozeph/v1.1.0 addressing #84 by adding a default export and modifying the readme to… — committed to brozeph/node-chess by brozeph 2 years ago
- further tweaking the imports and requires directives for #84 — committed to brozeph/node-chess by brozeph a year ago
FYI in case it helps anyone out: in order to unblock myself I published
@tmikeladze/chesswhich can be imported in a common js project. It has the changes from #88