# Proposal for Scripts 3.0 (ES Module Scripts)

**URL:** <https://forum.playcanvas.com/t/proposal-for-scripts-3-0-es-module-scripts/28026>\
**Category:** Suggestions & Feedback\
**Created:** [October 20, 2022, 3:03pm UTC](https://forum.playcanvas.com/t/proposal-for-scripts-3-0-es-module-scripts/28026 "2022-10-20T15:03:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [October 20, 2022, 3:03pm UTC](https://forum.playcanvas.com/t/proposal-for-scripts-3-0-es-module-scripts/28026/1 "2022-10-20T15:03:34Z")

</div>

Please let us know your feedback in the GitHub ticket!

> <https://github.com/playcanvas/engine/issues/4767>
>
> The current PlayCanvas script format was \[introduced\](https://blog.playcanvas.co…m/playcanvas-scripts-2-0/) in July 2016. PlayCanvas scripts are snippets of JavaScript that are (asynchronously) loaded and then, once loaded, immediately executed in global application scope.
> 
> The current PlayCanvas script format has a number of problems:
> 
> 1. The current default script template is still generated based on the ES5 feature set of JavaScript. This is looking increasingly antiquated in a world where ES Modules have become dominant. JavaScript has moved on considerably over the last 10 or so years.
> 2. Developers want to leverage tree shaking to generate an application bundle that only includes the code necessary to execute the application. The current script format is not compatible with tree shaking because it does not specify the specific symbols on which the code relies. ESM does this with the \`import\` statement.
> 3. Developers want to be able to run a build system (like Rollup, Webpack etc). This would allow them to run transpilers (e.g. Babel), minifiers (e.g. Terser) and so on. These build tools (or bundlers) tend to take ES Modules as input. Our current script format does not play nice with these bundlers.
> 4. While you can run PlayCanvas in Node if you use the ES5 build of the engine, the current script system cannot be used with the module build (or if you run the source directly in Node, as with our engine unit tests). When the scripts are loaded (by doing a dynamic \`import\` call), the \`pc\` namespace doesn't exist. The script would need to import what it needs.
> 5. Intellisense in VS Code (or the Code Editor's Monaco) does not work too well with \`ScriptType\`-based scripts. For example, attributes don't resolve correctly. An ES Module containing a class \_might\_ be a better approach.
> 
> So I propose that we investigate the development of a new script format that:
> 
> \* Is based on ES Module format.
> \* Is based on ES6 class syntax.
> \* Supports dynamic loading (say when running the Launch tab from the PlayCanvas Editor).
> \* Supports easy-to-use hot reloading.
> \* Supports being built into a bundle (by the likes of Rollup etc).
> \* Supports Intellisense well in VS Code/Monaco.
> \* Can be run in Node when running the engine as a module or from source modules (this is critical for unit testing in Node, say).
> \* Is compatible with TypeScript.
> 
> I welcome comments from the community on this proposal.

---

<div class="post-metadata">

**Author:** ![Mark\_Lundin](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mark_lundin/32/9629_2.png) [@Mark\_Lundin](https://forum.playcanvas.com/u/Mark_Lundin)\
**Post date:** [October 27, 2023, 11:57am UTC](https://forum.playcanvas.com/t/proposal-for-scripts-3-0-es-module-scripts/28026/2 "2023-10-27T11:57:41Z")

</div>

Just following up on this. We’ve now got a design doc and are gathering community feedback on this proposal. Please give this an upvote!

> **[\[RFC\] ES Modules · playcanvas/engine · Discussion #5770](https://github.com/playcanvas/engine/discussions/5770)**
>
> ES Modules This is a working doc that collates the discussion around ES Modules from #4767, outlines user pain points, current architectural roadblocks, and offers proposed solutions and roadmap. I...
