geckos.io: Compile error after upgrading to 2.0.0 using TypeScript

Describe the bug I get the following error after building the project with the new 2.0.0 version.

[ERROR] 11:38:21 Error: Must use import to load ES Module: /Users/robin/Projects/games/dogfight-online/node_modules/@geckos.io/server/lib/index.js
require() of ES modules is not supported.
require() of /Users/robin/Projects/games/dogfight-online/node_modules/@geckos.io/server/lib/index.js from /Users/robin/Projects/games/dogfight-online/server/src/index.ts is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/robin/Projects/games/dogfight-online/node_modules/@geckos.io/server/package.json.

I’m importing as follows:

import geckos from "@geckos.io/server";

I use ts-node-dev to compile my project as I’m in a TypeScript environment.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Would it be possible to ship two versions: an ESM one and a CJS one to have something like the below?

import geckos from "@geckos.io/server/cjs"; // Opt-in to CJS
import geckos from "@geckos.io/server"; // Default ESM

I think this would be useful for devs who are using a build system that outputs CJS.

this is a big issue!!

Why? It is working fine. You just have to learn how to use ECMAScript modules in Node.js.

Keep up the great work.

Thanks! I will.

Yes, it depends where your users live and what connection they have.
For a Starlink user, for example, a WebSocket Action Shooter will not be very enjoyable. But for most landlines, WebSockets is not drawback.