JavaScript Imports

Learn to use different methods to import JavaScript libraries with Python.

JavaScript imports

We covered a few different ways of importing JavaScript libraries into the scope of our Python projects early on. Moving forward, we’ll assume that you are using the Parcel web application bundler and npm to locally store copies of the JavaScript libraries that will be used in the project. That said, the primary import of a JavaScript library will use the Node.js require() function like this:

React = require('react')

This ES5 style statement will cause the application bundler to import the JavaScript library into the current namespace and assign it to the Python variable on the left of the statement. Once we do that, we can import the library into another Python module as a native Python object. By comparison, we might come across the same JavaScript import with ES6 syntax, which would look like this:

import React from 'react';
...