Skip to content

Bundling issues due to library dependency on shelljs #944

@webratz

Description

@webratz

Describe the bug
When using the library and bundling it with esbuild (in this case for use within AWS lambda) an error is thrown.

{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module './src/cat'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
  "trace": [
    "Runtime.ImportModuleError: Error: Cannot find module './src/cat'",
    "Require stack:",
    "- /var/task/index.js",
    "- /var/runtime/index.mjs",
    "    at _loadUserApp (file:///var/runtime/index.mjs:1000:17)",
    "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:21)",
    "    at async start (file:///var/runtime/index.mjs:1200:23)",
    "    at async file:///var/runtime/index.mjs:1206:1"
  ]
}

This is being caused not by this library, but the direct dependency shelljs.
The reason why I'm reporting this here is, that this is not seen as a bug there

As shelljs only seems to be used in very few places in this library, I'm wondering if it would be an option to remove the dependency and implement the few places it uses in a different way.

https://github.com/kubernetes-client/javascript/search?q=shelljs

** Client Version **
0.18.0

** Server Version **
e.g. 1.24.0

To Reproduce
Steps to reproduce the behavior:

  • Bundle any project that depends on @kubernetes/client-node with esbuild (or other bundlers)

Expected behavior
No error is thrown and the library can be used.

** Example Code**

import * as k8s from '@kubernetes/client-node';
const kc = new k8s.KubeConfig();
kc.loadFromDefault();

Environment (please complete the following information):

  • OS: macOs 12.6
  • NodeJS Version: 18
  • Cloud runtime: Lambda

Additional context
If you use AWS CDK NodejsFunction you can use the following bundling settings as a workaround

bundling: {
    forceDockerBundling: true,
    minify: false,
    keepNames: true,
    nodeModules: ['shelljs'],
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions