How to find out module import instructions when not in the docs?

Often in documentation for libraries, information will be given in the docs about how to import the module once it's been installed via npm. For example:

import React from "react" 

When this isn't given, how is it possible to know what should be imported to make use of the library?


For default imports (like the one you showed) you can choose any name you like.

For named exports you're going to have to dig into the source code to see which named exports exist. If a package doesn't even provide documentation on that, I wouldn't consider using it.


Projects setup with Modern frameworks like react, vue, angular come with built in build tool like webpack. It takes care of dependency tree of the project and only load necessary modules.

ex: Import { flatten } from lodash:

Above statement only includes flatten method in your bundle instead of whole lodash.

Regarding your question of what to import depends upon what's already installed and what exactly do you want to use.

Hope that clarifies.


For almost all libraries / packages, the package name is the one that you need to import.

For example, you run npm install react to install react into your project folder.

Notice how you wrote react while executing the command. This tells us that you installed a package called react.

Now to import it, you simply write:

import the_name_you_want_to_declare from 'the_package_name';

Now this syntax is only when the package has default exports.

For packages that don't have default exports, you should write:

import {the_named_export} from 'the_package_name';

Notice the curly braces around the declaration name to be used in that file.