-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chess.js not working in a typescript environment #335
Comments
Same issue |
Hi and thanks for the report. There's a new typescript version of chess.js in the dev branch that's about 95% feature complete. It's slated to be version 1.0.0. You can try it out by running the (untested) commands below: $ npm install https://github.com/jhlywa/chess.js#dev
$ cd node_modules/chess.js
$ npm run build Note that the 1.0.0 API uses camelCase instead of snake_case function calls. There are still a few planned changes (see #319) before this release becomes official. |
@jhlywa i ran the above commands and got these errors (i recognize you mentioned it is untested):
|
@933459 Perhaps you're running with an older version of typescript? I've only tested with 4.4.x and greater. Try adding a call to $ npm install https://github.com/jhlywa/chess.js#dev
$ cd node_modules/chess.js
$ npm install
$ npm run build |
thanks @jhlywa , yes i was accidentally using typescript 3.4. upgrading to typescript@latest allows the dev version of chess.js to build correctly per the directions above. appreciate your time on this. |
@jhlywa Awesome! I'm happy to hear you're converting this repo to TypeScript. 🙂 |
I am still getting the ERR_REQUIRE_ESM error on 1.0.0-beta.4 |
Here's a repo to reproduce the problem: https://github.com/neofight78/import-issue |
@neofight78 Thanks for the report. I'll spend a few days looking into supporting both ESM and commonjs. Worst case scenario, I could push an additional package/branch to NPM w/ commonjs support. |
Thank you 🙏 It's not an area I'm super familiar with otherwise I would offer to help. Perhaps tsup could be of some use? |
Version |
On the other hand, I cannot for the life of me figure out how to import the CommonJS beta5 version in a ES6 module project. I'm using beta4 right now, which works great in both browser and NodeJS (because I use modules for everything including Node). It seems like it may not even be possible for beta5 to work in the browser since it is CommonJS, at least not without Webpack or similar. Though I'm not an expert. I certainly couldn't get it working though. :( Perhaps it is possible to publish separate builds for each version? Not sure if NPM has a nice way to allow that, or if there is a more elegant solution. Sorry to complicate the situation further, and thanks for this great work! |
@pnb Thanks for the feedback and sorry for the breaking changes. @GabrielDelepine mentioned supporting both ESM and CommonJS should be possible via the |
Hello,
The chess.js module doesn't seem to work in a Typescript environment. (ERR_REQUIRE_ESM when importing)
Typescript by default outputs code with the "commonjs" module type. Unfortunately, chess.js only seem to support the ESM module type.
(Working with esnext as output module type is not really possible at the moment, see https://www.tsmean.com/articles/learn-typescript/typescript-module-compiler-option/)
I've made a minimal repository to reproduce the issue : https://github.com/mickev36/chessjsissue (run it with npx ts-node main.ts)
Switching a whole project to ESM modules just for chess.js seems problematic, since it would break pretty much all the other dependencies in projects. Transpiling the project also seems overkill for the task.
Can you please provide an implementation which works with a commonjs module type ? Or a way around it ?
Thanks
The text was updated successfully, but these errors were encountered: