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.

Error: "Cannot use import statement outside a module"

See original GitHub issue

Describe the bug

We were using the old version of this library (e.g. keycloak-admin), but realized it is no longer supported. So we went to replace it with the newer @keycloak/keycloak-admin-client.

When I install the package, and then include it in one of my files like this…

import KcAdminClient from '@keycloak/keycloak-admin-client';

I begin getting the following error when running my tests from Jest.

SyntaxError: Cannot use import statement outside a module

    > 1 | import KcAdminClient from '@keycloak/keycloak-admin-client';
        | ^

Jest has some suggestions, but it is unclear to me exactly why this is occurring. We are using Node 16.15.1.

I am assuming it has something to do with the way the @keycloak/keycloak-admin-client package is compiled when installed into my node_modules, but I really have no idea how to move forward.

Is there some help you can provide here? Thanks!

Version

Latest version of @keycloak/keycloak-admin-client

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Anything else?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jonkoopscommented, Aug 8, 2022

CommonJS and ESM interoperability is notoriously hard, so we’d rather stick to a standardized solution that everyone will be using in the future.

1reaction
gadielkallebcommented, Dec 1, 2022

“CommonJS and ESM interoperability is notoriously hard, so we’d rather stick to a standardized solution that everyone will be using in the future.”

@jonkoops it’s not like that, the vast majority of people/companies that are using this package still follow type commonsJS. this answer is a bit lazy (I say this with all due respect) but making a package like this available, changing it from one moment to another, and letting everyone manage to configure their projects is a bit of bad faith.

I say this because I’m having the same problem as @kevinswarner , and our product is in production and I can’t downgrade it because version 18 has a vulnerability pointed out by our sonarqube and we can’t update to version ^20.0.1 because it has this “problem” with ESM, complicated.

at least we managed to fork the project

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Uncaught SyntaxError: Cannot use import statement outside ...
This means that you're using the native source code in an unaltered/unbundled state, leading to the following error: Uncaught SyntaxError: ...
Read more >
Cannot use import statement outside a module [React ...
In this article, we talked about the SyntaxError: Cannot use import statement outside a module error in TypeScript and JavaScript. This error ...
Read more >
How to fix "cannot use import statement outside a module"
I stumbled on this error: Uncaught SyntaxError: cannot use import statement outside a module while importing a function from a JavaScript ...
Read more >
Cannot use import statement outside module in JavaScript
The "SyntaxError: Cannot use import statement outside a module" occurs when we use the ES6 Modules syntax in a script that was not...
Read more >
How to solve: cannot use import statement outside a module
When you see the error message Uncaught SyntaxError: cannot use import statement outside a module, it means you're using an import statement ......
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