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

Most upvoted comments

FYI in case it helps anyone out: in order to unblock myself I published @tmikeladze/chess which can be imported in a common js project. It has the changes from #88