question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile error after upgrading to 2.0.0 using TypeScript

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
Enijarcommented, Sep 24, 2021

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.

6reactions
yandeucommented, Aug 10, 2021

this is a big issue!!

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript compile errors after upgrading react native project
and It seems like the typescript packages are not compatible with their original packages. package.json dependencies "react": "17.0.2", "react- ...
Read more >
Migrating to AWS CDK v2 - AWS Documentation - Amazon.com
If you're using the CDK v2 Developer Preview, you have dependencies in your project on a Release Candidate version of the AWS CDK,...
Read more >
Working with JavaScript in Visual Studio Code
You are working with JavaScript or TypeScript code on vscode.dev or github.dev and VS Code is running in the browser. You open a...
Read more >
ts-node - npm
It is important to differentiate between errors from ts-node, errors from the TypeScript compiler, and errors from node . It is also important ......
Read more >
Documentation - TypeScript 3.9
When a line is preceded by a // @ts-expect-error comment, TypeScript will ... are in the middle of an upgrade between two different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found