Skip to content

updating package version results in ES Module errors when using NestJs #2219

Open
@dbrcplex

Description

@dbrcplex

I have been using "@kubernetes/client-node": "^0.18.1" in my package.json and it works.

If I update the version to 1.0.0 - "@kubernetes/client-node": "^1.0.0" I get errors:

"require() of ES Module /home/app/kubernetes-test/node_modules/@kubernetes/client-node/dist/index.js from /home/app/kubernetes-test/dist/app.service.js not supported.\nInstead change the require of index.js in /home/app/kubernetes-test/dist/app.service.js to a dynamic import() which is available in all CommonJS modules."

This is my import statement when using v 0.18.1

import * as k8s from '@kubernetes/client-node';

Based on the ES Module error I have removed that import and have tried this but it does not work:

const k8s = require('@kubernetes/client-node');
const kc = new k8s.KubeConfig();
kc.loadFromFile(KUBECONFIGSPATH + '/' + body.kubeconfig);

I have also tried a dynamic import and that also results in the same ES Module error.

await import('@kubernetes/client-node')
.then((k8s)=>{
const kc = new k8s.KubeConfig();
kc.loadFromFile(KUBECONFIGSPATH + '/' + body.kubeconfig);
const apiclient = kc.makeApiClient(k8s.CoreV1Api);

Based on what I have been reading it sounds like my package.json and/or tsconfig.json may also need to be updated but whatever combination(s) I have tried have also not worked.

Does anyone have a working example of using v1.0.0 and NestJS?

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions