Error: "Cannot use import statement outside a module"
See original GitHub issueDescribe 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:
- Created a year ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
CommonJS and ESM interoperability is notoriously hard, so we’d rather stick to a standardized solution that everyone will be using in the future.
“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