# How to import babylonjs modules into a project using typescript

**URL:** https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849
**Category:** Questions
**Tags:** documentation
**Created:** [July 25, 2020, 10:48pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849 "2020-07-25T22:48:32Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Ariel\_Gimenez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ariel_gimenez/32/471_2.png) [@Ariel\_Gimenez](https://forum.babylonjs.com/u/Ariel_Gimenez)
#### Post date: [July 25, 2020, 10:48pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/1 "2020-07-25T22:48:32Z")

</div>

Hello everyone, I’m still with a flappyBird approximately 2 months ago, I completed the project in a single file and in this way imported modules.

 ![Captura de pantalla_2020-07-25_19-30-13](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/f576edae5ed4b622c5b28d61dce5f3654680965c.png)  
The theme is to separate the project into several files, so that each file is 1 class, among them I have a main class called Main and from the HTML I search for the Main.js  
 ![Captura de pantalla_2020-07-25_19-34-50](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/e/e49e4c2450ea11401e27131aa23e4b7fa6805a84.png)  
 ![Captura de pantalla_2020-07-25_19-34-19](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/9/90f645a354e6f39c6ac2ca0857fc382095fd033b.png)  
When I had everything in 1 file this way it worked, but since I am separating the project into several files, “it doesn’t work anymore,” … Does anyone know how to solve this problem? Do you know any tutorial?  
As much as possible I don’t want to use npm since it considerably increases the size of the project since it links several files that if I later delete them to reduce the final size of the project they won’t work.

[https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/1/192931c3478f146a2c02704c9e9649dcab962a81.mp4](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/1/192931c3478f146a2c02704c9e9649dcab962a81.mp4)

 ![Captura de pantalla_2020-07-25_19-46-48](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/f817312698f4727bc444cd7929480e2740d4e4a4.png)

---

<div class="post-metadata">

### Author: ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)
#### Post date: [July 26, 2020, 1:08am UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/2 "2020-07-26T01:08:07Z")

</div>

Hi @Ariel_Gimenez, I think it’s looking for the folder `/babylon` but inside the same directory as the `index.html` file.

Maybe try moving `/babylon` from `/Cases ts` to one directory up or duplicating your `/babylon` folder to one directory up.

---

<div class="post-metadata">

### Author: ![JCPalmer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcpalmer/32/42_2.png) [@JCPalmer](https://forum.babylonjs.com/u/JCPalmer)
#### Post date: [July 26, 2020, 1:09pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/3 "2020-07-26T13:09:49Z")

</div>

Think you are probably doing it the hard way. Just add the Babylon.d.ts file to the source. References are mostly so transpiler knows what order to put multiple . TS files in.

---

<div class="post-metadata">

### Author: ![Ariel\_Gimenez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ariel_gimenez/32/471_2.png) [@Ariel\_Gimenez](https://forum.babylonjs.com/u/Ariel_Gimenez)
#### Post date: [July 26, 2020, 2:58pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/4 "2020-07-26T14:58:14Z")

</div>

@JCPalmer Hello I made this little project reproducing the problem.  
[import modules using inheritance with typescript babylonJS.zip](https://forum.babylonjs.com/uploads/short-url/uzLTe6yLu62Hf6VnEkgXK4tk6I6.zip) (1.7 MB)

As you will see in this project I have all the imported libraries as follows.

 ![Captura de pantalla_2020-07-26_11-51-44](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/febe11698c2022f77bd702dd1ebec450e4f67fce.png)

Create a main class that calls other classes using inheritance and trying to import modules in the same way into different files.

 ![Captura de pantalla_2020-07-26_11-52-46](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/7/7d7a5184952bd712617b5e5306cc5dc5243f1350.png) ![Captura de pantalla_2020-07-26_11-52-57](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/4/447294f76ffba89e2397856448cb3d48c60f2542.png) ![Captura de pantalla_2020-07-26_11-53-05](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/2/2c8f043b33dacc081df72949907daa232a5eaa98.png) ![Captura de pantalla_2020-07-26_11-53-31](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/fe9b3136ac907837ae5a03f0f6b15d75091dd0ea.png)

I also have some problems in tsconfig.json

 ![Captura de pantalla_2020-07-26_11-55-11](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/a/a2c94a4582c59016732c425aff27928c6cba3bd5.png)

I leave an example video as well.

[https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/4/48f838780806541e3efa87a766bef444a810b79d.mp4](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/4/48f838780806541e3efa87a766bef444a810b79d.mp4)

I really can’t find a solution to this, I mean if all the classes are in the same file it works, but when separating them they don’t work anymore … thank you very much for your time.

---

<div class="post-metadata">

### Author: ![Ariel\_Gimenez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ariel_gimenez/32/471_2.png) [@Ariel\_Gimenez](https://forum.babylonjs.com/u/Ariel_Gimenez)
#### Post date: [July 26, 2020, 3:03pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/5 "2020-07-26T15:03:46Z")

</div>

@gbz thanks, I reproduced the problem in this project, tell me if you can solve it. Thank you very much.  
[import modules using inheritance with typescript babylonJS.zip](https://forum.babylonjs.com/uploads/short-url/uzLTe6yLu62Hf6VnEkgXK4tk6I6.zip) (1.7 MB)

---

<div class="post-metadata">

### Author: ![Ariel\_Gimenez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ariel_gimenez/32/471_2.png) [@Ariel\_Gimenez](https://forum.babylonjs.com/u/Ariel_Gimenez)
#### Post date: [July 26, 2020, 3:26pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/6 "2020-07-26T15:26:46Z")

</div>

@gbz @JCPalmer Here is the project in a single file and it does not work either. Thanks for your answers.[Classes in typescript with babylonJs 1 file.zip](https://forum.babylonjs.com/uploads/short-url/2jLkgAhsZzcVKOKNNph5MsuGpwG.zip) (1.7 MB)

---

<div class="post-metadata">

### Author: ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)
#### Post date: [July 26, 2020, 8:05pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/7 "2020-07-26T20:05:39Z")

</div>

@Ariel_Gimenez

[ariel.zip](https://forum.babylonjs.com/uploads/short-url/Qf7uV0LrIYkMon9KCNXds9v7J0.zip) (2.5 MB)

This seems to work

`npm run build` builds the project  
`npm run launch` runs the project on [http://localhost/](http://localhost/)

---

<div class="post-metadata">

### Author: ![Ariel\_Gimenez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ariel_gimenez/32/471_2.png) [@Ariel\_Gimenez](https://forum.babylonjs.com/u/Ariel_Gimenez)
#### Post date: [July 27, 2020, 4:06pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/8 "2020-07-27T16:06:19Z")

</div>

@gbz Hi thank you very much, I see that you used npm, is there a way to do it without npm?  
you could record video showing how you make babylon modules work using typescript in different files, you don’t need to speak, I just want to see the process since I can’t do it.  
What technologies did you use to make it work with NPM, would you recommend a tutorial?

---

<div class="post-metadata">

### Author: ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)
#### Post date: [July 27, 2020, 8:03pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/9 "2020-07-27T20:03:40Z")

</div>

@Ariel_Gimenez, Node and npm was only used to serve the `index.html` file and its assets. Please feel free to not use Node and npm and serve the files as you did before.

In `package.json`, you can see that

- `npm run build` is `rm -rf ./js && rm -rf ./dist && tsc && webpack`  
(This deletes the `js/` and `dist/` folders and compiles using TypeScript and webpack (for client-side browser compatibility)
- `npm run launch` is `node server.js`  
(`server.js` is a Node script that only uses the `Express` framework to serve an `index.html` page and its assets. Please feel free to serve your page without Node and using whichever method you prefer.)

---

<div class="post-metadata">

### Author: ![LeJohn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lejohn/32/35093_2.png) [@LeJohn](https://forum.babylonjs.com/u/LeJohn)
#### Post date: [July 27, 2020, 8:29pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/10 "2020-07-27T20:29:43Z")

</div>

> [@Ariel\_Gimenez](#):
>
> What technologies did you use to make it work with NPM, would you recommend a tutorial?

You can take a look at this very complete “starter kit” project:

> [@Babylon.js project using typescript, webpack, es6 modules and other goodies](https://forum.babylonjs.com/t/babylon-js-project-using-typescript-webpack-es6-modules-and-other-goodies/10241):
>
> Hi gang, We had quite a lot of questions about babylon.js project issues, mainly regarding modules and webpack. How to build, how do debug, how to get started. So I made a small getting-started project that can be forked and can be used as the base to your new es6 project. It is available on github: It is basically everything you need to get started - debug environment, typescript hot-loading, full module support, production build and more. For now it is a very simple project - a plane, a …

---

<div class="post-metadata">

### Author: ![Ariel\_Gimenez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ariel_gimenez/32/471_2.png) [@Ariel\_Gimenez](https://forum.babylonjs.com/u/Ariel_Gimenez)
#### Post date: [July 28, 2020, 2:16pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/11 "2020-07-28T14:16:46Z")

</div>

@gbz Ok, thank you very much, I will take a few weeks to study webpack and node … I see that they are fundamental tools to continue with these technologies … Thank you for your time

---

<div class="post-metadata">

### Author: ![Ariel\_Gimenez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ariel_gimenez/32/471_2.png) [@Ariel\_Gimenez](https://forum.babylonjs.com/u/Ariel_Gimenez)
#### Post date: [July 28, 2020, 2:17pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/12 "2020-07-28T14:17:11Z")

</div>

Ok,thanks

---

<div class="post-metadata">

### Author: ![Ariel\_Gimenez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ariel_gimenez/32/471_2.png) [@Ariel\_Gimenez](https://forum.babylonjs.com/u/Ariel_Gimenez)
#### Post date: [August 6, 2020, 6:02pm UTC](https://forum.babylonjs.com/t/how-to-import-babylonjs-modules-into-a-project-using-typescript/12849/13 "2020-08-06T18:02:21Z")

</div>

After several days of researching I was able to compile webpack with typescript and babylon.js here is the github source code …  
Soon I will do a tutorial in Spanish.

> **[kone9/webpack-con-babylonJs-y-typescript](https://github.com/kone9/webpack-con-babylonJs-y-typescript)**
>
> En este proyecto utilizo webpack para compilar typescript mientras uso la librería 3D babylon.js - kone9/webpack-con-babylonJs-y-typescript
