Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!