Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
How to import require module in browser javascript

I want to make a jupyter notebook extension and I am following this repo . I needed to run python code using javascript for which I am trying to use the npm python-shell

To import the package, I tried using require module but its not working because it is not supposed to be run on browser and requires nodejs. I tried searching for other ways to run nodejs on browser and found stuff like browserify etc. However , the file main.js in the repo linked above is using the require module comfortably. How is it doing so? What am I missing? Below is the code and the error I get in the browser. I have installed require and python-shell module using npm already.

Code:

define(['require','PythonShell','base/js/namespace', 'base/js/events'], function (require,Jupyter, events) {
  

  var PythonShell = require('python-shell');
  PythonShell.runString('x=1;print(x)',null,function(err,results) {
    console.log(results);
  });

  function load_ipython_extension() {
    console.log("Hello World");
  }
  return {
    load_ipython_extension: load_ipython_extension,
  };
});

Error:

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It looks like the library you are trying to use, python shell was designed for node.js, as stated in their package description:

A simple way to run Python scripts from Node.js with basic but efficient inter-process communication and better error handling.

Because of that, you cannot use this package in the browser. There are probably lots of alternatives, and I found this package through some quick googling: pyodide (note, I have never used this myself, I just found it).

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda