You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Upgrade to 0.22.2 fails due to use of new major version of client-node. #2014
Describe the bug
When upgraded to latest version 0.22.2 of this library getting the following error:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/app/node_modules/openid-client/build/index.js from /home/app/node_modules/@kubernetes/client-node/dist/oidc_auth.js not supported.
Instead change the require of index.js in /home/app/node_modules/@kubernetes/client-node/dist/oidc_auth.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/home/app/node_modules/@kubernetes/client-node/dist/oidc_auth.js:5:35)
at /home/app/node_modules/@kubernetes/client-node/dist/oidc_auth_delayed.js:44:70
at async DelayedOpenIDConnectAuth.applyAuthentication (/home/app/node_modules/@kubernetes/client-node/dist/oidc_auth_delayed.js:44:22)
at async KubeConfig.apply(--- cut ---)
at async KubeConfig.applyOptions (/home/app/node_modules/@kubernetes/client-node/dist/config.js:388:9)
at async KubeConfig.applyToRequest (/home/app/node_modules/@kubernetes/client-node/dist/config.js:110:9)
This appears to be due to using the new version of client-node.
** Client Version ** 0.22.2
** Server Version **
e.g. 1.19.1
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
** Example Code**
Code snippet for what you are doing
Environment (please complete the following information):
OS: [e.g. Windows, Linux]
NodeJS Version [eg. 10]
Cloud runtime [e.g. Azure Functions, Lambda]
Additional context
Add any other context about the problem here.
It looks like #1969 bumped the openid-client dependency from 5.7.0 to 6.1.3. Looking at the v6.0.0 release notes, that dependency switched to being an ESM module. Since the TypeScript code is transpiled to use require(), I'm guessing that explains the error.
I'm curious what the maintainers would think about reverting #1969 on the v0.x release line, and using this as a reason to move the 1.x release line to ESM. I think that would cause the fewest future headaches.
Is the intent then to make the client ESM-only as of v1? That's a rather disruptive change if v0.x is going to be discontinued, i.e. it forces people to upgrade to Node.js 22 or to switch to ESM if they want to continue using this?
Additionally, in the light of #1693 (comment) (i.e. the final v1 potentially getting released in the coming week), is the intent to merge this before then or are we going to get a v2 shortly?
I think we want to have the v1.x ESM to be future proof.
We could still release v0.x with the changed k8s API, however, I personally would like to stop that as early as possible as maintaining two main branches is a big burden.
You could still use the already released version, most of the time they are even compatible with newer k8s versions but it also depends a lot of which features you are using.
I think we should probably continue releasing 0.x like 2 versions to give people time to adapt to that change after promoting v1.x as the official release.
Going to play the devil's advocate a little bit (I don't have a major problem with going ESM-only, assuming the require(ESM) support in Node.js v22+ is less experimental than the documentation implies1).
Aside from the API change (which is very nice!), one of the most attractive features of v1 is the switch to fetch. Having to ignore the various alerts about old vulnerabilities in request is something that is very annoying in the 0.x. The switch to ESM will significantly raise the barrier for switching - people will either have to upgrade to Node.js v22 (which they should, in the next 12-24 months anyways, but we all know how these things go) or they will have to rewrite their code in ESM (which is expensive and is very hard to justify in terms of cost vs benefit).
Is there any chance v1 could be released in dual-mode? I haven't done this, but there's plenty of packages in the ecosystem that release both - CJS and ESM inside? Or is that affected by dependencies?
Footnotes
Prediction: removing the command line flag will make people start using it now, and that means the implementation will be effectively locked in - changing it even behind a major version would be very disruptive. ↩
As you mentioned, require(esm) is now available by default on Node v22 and v23. I recall seeing discussion about possibly unflagging it on v20 if things go well, but I'm having trouble finding the discussion right now. My experience has been that require(esm) works well, and since this package doesn't have top level await, it can be used here. If it does get backported to v20, and with v18 going EOL in April, I think that provides pretty good coverage. Of course, there is also dynamic import() for people who are unwilling to move to ESM.
Of course, all of this is also driven by dependencies that are increasingly moving to ESM. As someone who very strongly prefers CJS over ESM, even I have to say I just don't think it's worth the maintenance burden. Resisting ESM at this point is kind of like trying to kick water uphill 😄.
This change is causing problems for me. The library doesn't work out of the box anymore when imported from within a NextJS application, and I can't get it to work with Jest either.
@christhegrand are you using the v0.x release line or the v1.x release line? If it is the v0.x branch, I think a patch reverting #1969 (or a similar code change) might do the trick for people that can't update yet.
Guys this is a useful library! Please, don't join the blasted ESM-only Taliban club (=== those nasty people believing it's ESM or death)!
There is no point of doing this, really! In Node land, this is far for being future proof! This is just a disruptive change that will leave many people with vulnerabilities or bugs that will never be fixed, for what? Making less than 15% devs happy?
It is extremely easy to build a TS package for both CJS and ESM nowadays, and leave the developers choose what to do, and you can turn to ESM later on, when the node ecosystem is more mature (I predict no less than 3 years).
Take me, I am tied to Node 20 right now...
❯ node --experimental-require-module
Welcome to Node.js v20.17.0.
Type ".help"for more information.
> (node:85321) ExperimentalWarning: Support forloading ES Moduleinrequire() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
> var kc = require('@kubernetes/client-node')
Uncaught RangeError: Maximum call stack size exceeded
at Object.openSync (node:fs:570:18)
at readFileSync (node:fs:452:35)
at getSourceSync (node:internal/modules/esm/load:85:14)
at defaultLoadSync (node:internal/modules/esm/load:201:32)
at ModuleLoader.getModuleWrapForRequire (node:internal/modules/esm/loader:362:24)
at new ModuleJobSync (node:internal/modules/esm/module_job:276:32)
at ModuleLoader.getModuleWrapForRequire (node:internal/modules/esm/loader:403:11)
at new ModuleJobSync (node:internal/modules/esm/module_job:276:32)
at ModuleLoader.getModuleWrapForRequire (node:internal/modules/esm/loader:403:11)
there aren't any workarounds. Jest/TS-Jest even worse.
Solution
In many dual libraries I need to build, I use tsup, a blazing fast builder that makes this kind of tasks easy now, in 2025.
This is the tsup.config.ts I am using and I believe this can be easily be adapted for this project
importtype{Options}from'tsup';constenv=process.env.NODE_ENV;exportconsttsup: Options={publicDir: './src/public/',splitting: true,sourcemap: true,// source map is only available in prodclean: true,// rimraf disrdts: true,// generate dts file for main moduleformat: ['cjs','esm'],// generate cjs and esm filesminify: env==='production',bundle: true,skipNodeModulesBundle: true,// noExternal: ['packages that need to be bundled'],entryPoints: ['src/index.ts'],watch: false,target: 'esnext',outDir: 'dist',entry: ['src/index.ts']};
You won't need big changes for tsconfig but I can provide some assist if you need.
For what it's worth, I did eventually get this library to work with Jest by using the hack mentioned here, but it's pretty gross. I hope this helps anyone who finds this page while trying to upgrade.
@lamuertepeluda the issue is not about transpiling this library to CJS and ESM. The issue is that we have multiple dependencies that have already moved to being ESM only.
there aren't any workarounds.
Have you tried dynamic import? If you have found a bug in Node's --experimental-require-module functionality, I encourage you to open an issue on the Node core issue tracker, as I believe they are currently in the process of trying to backport unflagged require(esm). require()ing this module does work on Node 22, so presumably this is a Node 20 bug.
Side note: Would you mind moderating your comment relating to the Taliban. I'd say that is off-topic at best.
I'm going to close this. At this point, I think this issue has run its course. For the v0.x branch, I think rolling back openid-client might still be on the table though if anyone wants to pursue that.
Then I updated the tests to look for tests files in the directory where the Typescript files for the tests were located instead of in the directory where the compiled JS files were located.
@christhegrand
Thanks a lot for sending your configuration. It did not work for me out of the box - I assume because we were using different versions of the library. Here is a summary
install the newest version of jest (for me it only works with 29.3.2 but not with 29.3.1)
the jose library also needs to be excluded
there is no need for a transformts-jest configuration per ESM node_module. Excluding the libraries in transformIgnorePatterns is enough.
tsconfig.json needs to contain "esModuleInterop": true
So this is the jest.config.js:
module.exports = {
testEnvironment: 'node',
preset: 'ts-jest',
moduleFileExtensions: ['js', 'json', 'ts', 'tsx', 'jsx', 'node'],
transform: {
// (Added support for .tsx files but not required)
'^.+\\.(t|j)sx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.test.json',
},
],
// (No need for module specific ts-jest configurations)...
},
transformIgnorePatterns: [
// Added jose library (probably this ESM dependency was added in the newer versions)
// This will work for @kuberenets/client-node version 1.1.2
'/node_modules/(?!(@kubernetes/client-node|openid-client|oauth4webapi|jose)/)',
],
};
This is the tsconfig.json:
{
"compilerOptions": {
"module": "commonjs" /* Specify what module code is generated. */,
// THIS IS IMPORTANT!
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
},
"include": [
"src/**/*" // Include all files in the 'src' folder
]
}
This change is causing problems for me. The library doesn't work out of the box anymore when imported from within a NextJS application, and I can't get it to work with Jest either.
@christhegrand Did you get this issue resolved with your nextjs app or just the jest part? I am having trouble with the client version 1.0.0+ working within my nextjs app.
I can't remember now how I addressed the issues with importing from Next. We've since modified our code so we don't need to use this library at all and are about to remove the dependency.
Activity
brendandburns commentedon Nov 4, 2024
I'll try to repro this. I would have thought that the unit tests for this code would have failed though.
Do you have a snippet of code that reproduces this?
Also, what version of Node are you using?
cjihrig commentedon Nov 4, 2024
It looks like #1969 bumped the openid-client dependency from 5.7.0 to 6.1.3. Looking at the v6.0.0 release notes, that dependency switched to being an ESM module. Since the TypeScript code is transpiled to use
require(), I'm guessing that explains the error.cjihrig commentedon Nov 4, 2024
Similar to what I mentioned in #1975 - it might be worth running the tests against the transpiled code.
cjihrig commentedon Nov 18, 2024
I'm curious what the maintainers would think about reverting #1969 on the v0.x release line, and using this as a reason to move the 1.x release line to ESM. I think that would cause the fewest future headaches.
mstruebing commentedon Nov 18, 2024
@brendandburns I think that would be a very valid breaking change.
what do you think?
cjihrig commentedon Nov 23, 2024
@brendandburns do you have any thoughts on #2014 (comment)?
brendandburns commentedon Nov 24, 2024
I'm ok with that.
src: convert project from CJS to ESM
src: convert project from CJS to ESM
src: convert project from CJS to ESM
dominykas commentedon Dec 5, 2024
Is the intent then to make the client ESM-only as of v1? That's a rather disruptive change if v0.x is going to be discontinued, i.e. it forces people to upgrade to Node.js 22 or to switch to ESM if they want to continue using this?
Additionally, in the light of #1693 (comment) (i.e. the final v1 potentially getting released in the coming week), is the intent to merge this before then or are we going to get a v2 shortly?
mstruebing commentedon Dec 5, 2024
I think we want to have the v1.x ESM to be future proof.
We could still release v0.x with the changed k8s API, however, I personally would like to stop that as early as possible as maintaining two main branches is a big burden.
You could still use the already released version, most of the time they are even compatible with newer k8s versions but it also depends a lot of which features you are using.
I think we should probably continue releasing 0.x like 2 versions to give people time to adapt to that change after promoting v1.x as the official release.
What do you think @brendandburns ?
dominykas commentedon Dec 5, 2024
Going to play the devil's advocate a little bit (I don't have a major problem with going ESM-only, assuming the require(ESM) support in Node.js v22+ is less experimental than the documentation implies1).
Aside from the API change (which is very nice!), one of the most attractive features of v1 is the switch to
fetch. Having to ignore the various alerts about old vulnerabilities inrequestis something that is very annoying in the 0.x. The switch to ESM will significantly raise the barrier for switching - people will either have to upgrade to Node.js v22 (which they should, in the next 12-24 months anyways, but we all know how these things go) or they will have to rewrite their code in ESM (which is expensive and is very hard to justify in terms of cost vs benefit).Is there any chance v1 could be released in dual-mode? I haven't done this, but there's plenty of packages in the ecosystem that release both - CJS and ESM inside? Or is that affected by dependencies?
Footnotes
Prediction: removing the command line flag will make people start using it now, and that means the implementation will be effectively locked in - changing it even behind a major version would be very disruptive. ↩
cjihrig commentedon Dec 5, 2024
As you mentioned,
require(esm)is now available by default on Node v22 and v23. I recall seeing discussion about possibly unflagging it on v20 if things go well, but I'm having trouble finding the discussion right now. My experience has been thatrequire(esm)works well, and since this package doesn't have top level await, it can be used here. If it does get backported to v20, and with v18 going EOL in April, I think that provides pretty good coverage. Of course, there is also dynamicimport()for people who are unwilling to move to ESM.Of course, all of this is also driven by dependencies that are increasingly moving to ESM. As someone who very strongly prefers CJS over ESM, even I have to say I just don't think it's worth the maintenance burden. Resisting ESM at this point is kind of like trying to kick water uphill 😄.
christhegrand commentedon Jan 2, 2025
This change is causing problems for me. The library doesn't work out of the box anymore when imported from within a NextJS application, and I can't get it to work with Jest either.
cjihrig commentedon Jan 3, 2025
@christhegrand are you using the v0.x release line or the v1.x release line? If it is the v0.x branch, I think a patch reverting #1969 (or a similar code change) might do the trick for people that can't update yet.
christhegrand commentedon Jan 3, 2025
This is when using 1.0.0.
lamuertepeluda commentedon Jan 15, 2025
Guys this is a useful library! Please, don't join the blasted ESM-only Taliban club (=== those nasty people believing it's ESM or death)!
There is no point of doing this, really! In Node land, this is far for being future proof! This is just a disruptive change that will leave many people with vulnerabilities or bugs that will never be fixed, for what? Making less than 15% devs happy?
It is extremely easy to build a TS package for both CJS and ESM nowadays, and leave the developers choose what to do, and you can turn to ESM later on, when the node ecosystem is more mature (I predict no less than 3 years).
Take me, I am tied to Node 20 right now...
there aren't any workarounds. Jest/TS-Jest even worse.
Solution
In many dual libraries I need to build, I use tsup, a blazing fast builder that makes this kind of tasks easy now, in 2025.
This is the
tsup.config.tsI am using and I believe this can be easily be adapted for this projectYou won't need big changes for tsconfig but I can provide some assist if you need.
christhegrand commentedon Jan 15, 2025
For what it's worth, I did eventually get this library to work with Jest by using the hack mentioned here, but it's pretty gross. I hope this helps anyone who finds this page while trying to upgrade.
cjihrig commentedon Jan 15, 2025
@lamuertepeluda the issue is not about transpiling this library to CJS and ESM. The issue is that we have multiple dependencies that have already moved to being ESM only.
Have you tried dynamic import? If you have found a bug in Node's
--experimental-require-modulefunctionality, I encourage you to open an issue on the Node core issue tracker, as I believe they are currently in the process of trying to backport unflaggedrequire(esm).require()ing this module does work on Node 22, so presumably this is a Node 20 bug.Side note: Would you mind moderating your comment relating to the Taliban. I'd say that is off-topic at best.
k8s-triage-robot commentedon Apr 15, 2025
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
cjihrig commentedon Apr 15, 2025
I'm going to close this. At this point, I think this issue has run its course. For the v0.x branch, I think rolling back openid-client might still be on the table though if anyone wants to pursue that.
philippkolbe commentedon Apr 30, 2025
@christhegrand Could you share your solution? I tried the proposed setup from the issue you linked but that did not work for me.
So, I am still stuck on getting jest to work with the kubernetes client-node library.
And looks like several other people from this stackoverflow post are stuck as well.
christhegrand commentedon Apr 30, 2025
In order to make this library work with Jest, I added this transform logic to the jest.config.js file that ts-jest was using:
and I added a new tsconfig file specifically for the tests:
Then I updated the tests to look for tests files in the directory where the Typescript files for the tests were located instead of in the directory where the compiled JS files were located.
philippkolbe commentedon May 1, 2025
@christhegrand
Thanks a lot for sending your configuration. It did not work for me out of the box - I assume because we were using different versions of the library. Here is a summary
joselibrary also needs to be excludedtransformts-jestconfiguration per ESM node_module. Excluding the libraries intransformIgnorePatternsis enough.tsconfig.jsonneeds to contain"esModuleInterop": trueSo this is the
jest.config.js:This is the
tsconfig.json:And this is
tsconfig.test.json(unchanged):Finally, you can import the library like this:
I also set up a stackblitz with a minimal sample which works for
@kuberenets/client-nodeversion1.1.2(runnpm run test):https://stackblitz.com/edit/stackblitz-starters-un7zge3j?file=jest.config.js
saulrobe commentedon Oct 6, 2025
@christhegrand Did you get this issue resolved with your nextjs app or just the jest part? I am having trouble with the client version 1.0.0+ working within my nextjs app.
christhegrand commentedon Oct 6, 2025
I can't remember now how I addressed the issues with importing from Next. We've since modified our code so we don't need to use this library at all and are about to remove the dependency.