Skip to content

nodejs sdk not working with type "module" #1029

@nikhlagrwl

Description

@nikhlagrwl

Describe the bug
I tried using the @e2b/code-interpreter js sdk but is failing in type: module

To Reproduce
Steps to reproduce the behavior:

node version - v20.6.1
package version - 2.7.0

sample code snippet -

import { Sandbox } from '@e2b/code-interpreter'

const sbx = await Sandbox.create()
await sbx.runCode('x = 1')

const execution = await sbx.runCode('x+=1; x')
console.log(execution.text)  // outputs 2

await sbx.terminate();

Error stack trace -

/Users/user/Desktop/nikhil/e2b_project/node_modules/e2b/dist/index.js:2455
var import_chalk = __toESM(require("chalk"));
                           ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/user/Desktop/nikhil/e2b_project/node_modules/chalk/source/index.js from /Users/user/Desktop/nikhil/e2b_project/node_modules/e2b/dist/index.js not supported.
Instead change the require of /Users/user/Desktop/nikhil/e2b_project/node_modules/chalk/source/index.js in /Users/user/Desktop/nikhil/e2b_project/node_modules/e2b/dist/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/user/Desktop/nikhil/e2b_project/node_modules/e2b/dist/index.js:2455:28)
    at Object.<anonymous> (/Users/user/Desktop/nikhil/e2b_project/node_modules/@e2b/code-interpreter/dist/index.js:62:25) {
  code: 'ERR_REQUIRE_ESM'
}

A clear and concise description of what you expected to happen.

Browser console output
Console logs from your browser's developer tool console.

Terminal commands & output
Commands you used to start the app and the terminal output.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macos

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions