Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported. #72

Open
shotexa opened this issue Jul 6, 2022 · 2 comments
Open

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported. #72

shotexa opened this issue Jul 6, 2022 · 2 comments

Comments

@shotexa
Copy link

shotexa commented Jul 6, 2022

I'm getting the error when trying to import a library in my code using the following syntax

import {
  SomeObject
} from 'library';

the error looks like this:

node:internal/modules/cjs/loader:1150
      throw err;
      ^

Error [ERR_REQUIRE_ESM]: require() of ES Module <Folder where notebook is located>/node_modules/<library>/dist/index.js from <Folder where notebook is located>/src.js not supported.
Instead change the require of index.js in <Folder where notebook is located>/src.js to a dynamic import() which is available in all CommonJS modules.
    at Object.apply (/usr/local/lib/node_modules/tslab/dist/executor.js:63:24)
    at evalmachine.<anonymous>:22:26
    at evalmachine.<anonymous>:25:3
    at sigintHandlersWrap (node:vm:268:12)
    at Script.runInThisContext (node:vm:127:14)
    at Object.runInThisContext (node:vm:305:38)
    at Object.execute (/usr/local/lib/node_modules/tslab/dist/executor.js:162:38)
    at JupyterHandlerImpl.handleExecuteImpl (/usr/local/lib/node_modules/tslab/dist/jupyter.js:219:38)
    at /usr/local/lib/node_modules/tslab/dist/jupyter.js:177:57
    at async JupyterHandlerImpl.handleExecute (/usr/local/lib/node_modules/tslab/dist/jupyter.js:177:21)
    at async ZmqServer.handleExecute (/usr/local/lib/node_modules/tslab/dist/jupyter.js:375:25)
    at async ZmqServer.handleShellMessage (/usr/local/lib/node_modules/tslab/dist/jupyter.js:320:21) {
  code: 'ERR_REQUIRE_ESM'
}

If that is a problem with my library and not with tslab kernel itself, could you tell me what it is?

Node - 16.7.0
jupyter --version

IPython          : 8.4.0
ipykernel        : 6.15.0
ipywidgets       : 7.7.1
jupyter_client   : 7.3.4
jupyter_core     : 4.10.0
jupyter_server   : not installed
jupyterlab       : not installed
nbclient         : 0.6.6
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : 5.3.1
traitlets        : 5.3.0

OS - MacOS Monterey 12.4

@devYonz
Copy link

devYonz commented Dec 2, 2022

Did you figure it out? I'm expecting that tslab is wrapping around node and doesn't support esm and maybe something like this could work https://github.com/standard-things/esm

Context about ESM and CommonJS : https://formidable.com/blog/2021/node-esm-and-exports/

The dynamic import() which is available in all CommonJS modules seems to give away that the imports are trying to be loaded in a commonJS format

@KhalfaniW
Copy link

KhalfaniW commented May 10, 2023

tslab runs in a node vm and
esm cannot run in a vm

There is a similar problem in ijavascript

However they found a workaround: require("esm-hook"); then whatever require whatever package was needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants