# How to use 'import' in P5?

**URL:** <https://discourse.processing.org/t/how-to-use-import-in-p5/12774>\
**Category:** p5.js\
**Created:** [July 18, 2019, 2:52am UTC](https://discourse.processing.org/t/how-to-use-import-in-p5/12774 "2019-07-18T02:52:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HuXiaoer](https://avatars.discourse-cdn.com/v4/letter/h/4da419/32.png) [@HuXiaoer](https://discourse.processing.org/u/HuXiaoer)\
**Post date:** [July 18, 2019, 2:52am UTC](https://discourse.processing.org/t/how-to-use-import-in-p5/12774/1 "2019-07-18T02:52:29Z")

</div>

In P5.js, how to use ES6’s import in top of sketch.js?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 18, 2019, 11:35am UTC](https://discourse.processing.org/t/how-to-use-import-in-p5/12774/2 "2019-07-18T11:35:01Z")

</div>

Do you mean JS’ native ECMAScript Modules (ESM) by the way: 🕶  
[ExploringJS.com/es6/ch\_modules.html](http://ExploringJS.com/es6/ch_modules.html)

Unfortunately, p5js library isn’t yet natively “importable” by JS newest `import` keyword, nor by its corresponding builtin **import()** function: 😿

> **[import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)**
>
> The static import statement is used to import bindings which are exported by another module.

Actually, even very famous libraries/frameworks like React aren’t compatible w/ it yet w/o relying on some other 3rd-party solutions: 😳

> **[lukejacksonn/es-react](https://github.com/lukejacksonn/es-react)**
>
> ES6 module exposing the latest version of react and react-dom - lukejacksonn/es-react

However, even though p5js isn’t itself compatible w/ this latest JS feature, we can still split our own sketches as ES modules, like I did once for my sketch “Ball-in-the-Chamber”: ➗

- [GitHub.com/GoSubRoutine/Ball-in-the-Chamber/tree/master/p5js-instance](http://GitHub.com/GoSubRoutine/Ball-in-the-Chamber/tree/master/p5js-instance)
- [GoSubRoutine.GitHub.io/Ball-in-the-Chamber/p5js-instance/](http://GoSubRoutine.GitHub.io/Ball-in-the-Chamber/p5js-instance/)
