# STLLoader in Vue.js Error

**URL:** <https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068>\
**Category:** Questions\
**Tags:** vue, stl-loader\
**Created:** [June 12, 2019, 4:08pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068 "2019-06-12T16:08:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 12, 2019, 4:08pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/1 "2019-06-12T16:08:17Z")

</div>

Hi all,

I have been trying to implement Three.js in Vue.js and i have been able to create a scene where i am capable to create a bunch of cubes with no problem. All that works as it should. My main issue is within the STLLoader, as im in need to load an STL Object into the scene.

I´m using npm libraries (‘three’ for the basic features such as scene, light, orbitcontrols…). But for Loaders i have used the following npm libraries:

- ‘three-full’: This library ends up with no errors (aparently) when loading the STL Object but it does not appear in the scene.
- ‘three-stl-loader’: This library does its job to load the STL Object as it enters the loop to read the faces and vertices of the object before loading, but the loop ends up at face 20, vertice 2 with the error “Uncaught RangeError: Offset is outside the bounds of the DataView”

The STL Objects i am trying to load were being loaded before with three.js in a local HTML page, now im moving it to Vue.js and I have tryed I think everything I could.

Any help will be really appreciated in order to load an STL Object into Vue.js using Three.

Thank you very much.

J.Sancho

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 12, 2019, 5:56pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/2 "2019-06-12T17:56:08Z")

</div>

Can you please share the STL file in this thread?

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 13, 2019, 8:28am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/3 "2019-06-13T08:28:20Z")

</div>

Yes, here you have it 🙂

[head.stl](https://discourse.threejs.org/uploads/short-url/ijHtgUxfrRHUMgHZX0uEwhGIhgy.stl) (3.5 MB)

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 13, 2019, 9:34am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/4 "2019-06-13T09:34:30Z")

</div>

I can load your file without the mentioned error with the latest version of `STLLoader`.

I suggest you stop using unofficial npm packages like `three-full` and `three-stl-loader` and use the official modules from the `three` npm package instead. As mentioned in the following guide (section `Importable Examples`) all frequently used classes from the examples directory are available as ES6 modules.

[https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules](https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules)

Also related: [Many new modules with three.js R105](https://discourse.threejs.org/t/many-new-modules-with-three-js-r105/7869)

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 13, 2019, 9:53am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/5 "2019-06-13T09:53:15Z")

</div>

how did you manage to load the file? Because i have used the ‘three’ npm package but did not manage it to work, can you provide an example code? Just to make sure i´m not doing anything wrong.

Thank you very much for all the help 🙂

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 13, 2019, 9:56am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/6 "2019-06-13T09:56:45Z")

</div>

I just replaced one of the files in the official STL example: [https://threejs.org/examples/webgl\_loader\_stl](https://threejs.org/examples/webgl_loader_stl)

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 13, 2019, 10:31am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/7 "2019-06-13T10:31:46Z")

</div>

Hi again, I have been trying to use the ‘three’ npm package as you told me to do, but I keep getting an error that THREE.STLLoader is not a constructor. Taking a look to the files in the three package, i cannot see the STLLoader.js file inside the loader directory in three.

> **[three](https://www.npmjs.com/package/three)**
>
> JavaScript 3D library

This is the official three npm package right?

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 13, 2019, 10:38am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/8 "2019-06-13T10:38:52Z")

</div>

Yes it is. The module is located here:

> <https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/STLLoader.js>

You can import it like so:

```auto
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';

```

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 13, 2019, 11:23am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/9 "2019-06-13T11:23:23Z")

</div>

I have tried importing it as you say, it looks like it works (with breakpoints i can see it enters the STLLoader.js) but it returns an error:

 ![THREE_error](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/7/7ee4d7ec3579c57d37d40723aa37b25da026e2fc.png)

The way i do it is:  
`import { STLLoader } from 'three/examples/js/loaders/STLLoader.js'`

and then call it as:

`var loader = new STLLoader();`

Is this correct or I am missing something?

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 13, 2019, 1:04pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/10 "2019-06-13T13:04:21Z")

</div>

Ok, so right know i manage to clean the error by downloading it again and right now is not giving me any errors.

But the head is not loading on the scene, i have put a breakpoint inside the call function for the `loader.load` and it never enters in this function.

I will continue investigating this, if you can guess why this could be happening please tell me and I will give it a go.

Thanks for all the help 🙂

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 13, 2019, 1:20pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/11 "2019-06-13T13:20:27Z")

</div>

Ok, so getting inside the STLLoader.js and putting some breakpoints, I have managed to see where it goes off. So in the following lines from STLLoader.js:

```
for ( var face = 0; face < faces; face ++ ) {

				var start = dataOffset + face * faceLength;
				var normalX = reader.getFloat32( start, true );
				var normalY = reader.getFloat32( start + 4, true );
				var normalZ = reader.getFloat32( start + 8, true );

				if ( hasColors ) {

					var packedColor = reader.getUint16( start + 48, true );

					if ( ( packedColor & 0x8000 ) === 0 ) {

						// facet has its own unique color

						r = ( packedColor & 0x1F ) / 31;
						g = ( ( packedColor >> 5 ) & 0x1F ) / 31;
						b = ( ( packedColor >> 10 ) & 0x1F ) / 31;

					} else {

						r = defaultR;
						g = defaultG;
						b = defaultB;

					}

				}

				for ( var i = 1; i <= 3; i ++ ) {

					var vertexstart = start + i * 12;

					vertices.push( reader.getFloat32( vertexstart, true ) );
					vertices.push( reader.getFloat32( vertexstart + 4, true ) );
					vertices.push( reader.getFloat32( vertexstart + 8, true ) );

					normals.push( normalX, normalY, normalZ );

					if ( hasColors ) {

						colors.push( r, g, b );

					}

				}

			}

```

It gets to work and start doing both loops (faces and vertices) but it stops and quits (without any warnings or errors or anything it just finish) on face 20 (the list is more larger than 20) and vertice 2 (when is 3 vertices per face).

Why can this be happening?

Thanks for all the help you can provide 🙂

J.Sancho

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 13, 2019, 1:48pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/12 "2019-06-13T13:48:55Z")

</div>

> [@Javier\_Sancho](#):
>
> import { STLLoader } from ‘three/examples/js/loaders/STLLoader.js’

You use the wrong path to `STLLoader`. The module version of the loader is in the `jsm` directory (not `js`).

```js
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js'

```

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 13, 2019, 1:49pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/13 "2019-06-13T13:49:40Z")

</div>

> [@Javier\_Sancho](#):
>
> Why can this be happening?

Not sure so far. I’m currently not into the STL standard so this might take a while until I can provide feedback.

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 13, 2019, 2:56pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/14 "2019-06-13T14:56:25Z")

</div>

Yes, the path for the github repository is `three/examples/jsm/loaders/STLLoader.js`

But the path from the npm package is `three/example/js/loaders/STLLoader.js`

Anyways, the last updates I have given is using the path from the github repository and it still does not get to work. It is like during the process to read the STL file it breaks. But it does not give any error back.

Will keep tracking this, if you have any news or there is anything I could try that you can think of, please tell me.

Thanks for all the help you already provided 🙂

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 13, 2019, 3:00pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/15 "2019-06-13T15:00:43Z")

</div>

> [@Javier\_Sancho](#):
>
> But the path from the npm package is `three/example/js/loaders/STLLoader.js`

I don’t think this is correct if you want to use the ES6 module version.

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 14, 2019, 8:11am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/16 "2019-06-14T08:11:04Z")

</div>

So I managed to see the error that is happening when getting on the faces loop at face 20 vertice 2, I am getting the following error (not showing on console):

`Offset is outside the bounds of the DataView`

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 14, 2019, 9:32am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/17 "2019-06-14T09:32:20Z")

</div>

Related:

> <https://github.com/enspiral-cherubi/three-stl-loader/issues/8>

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 14, 2019, 10:08am UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/18 "2019-06-14T10:08:49Z")

</div>

Um,I have not problems on macOS and Chrome/Firefox/Safari:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/3/31bea49af28f9332a79f25d6a7342efbe1a09f0b.jpeg)

What OS are you using?

---

<div class="post-metadata">

**Author:** ![Javier\_Sancho](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/javier_sancho/32/5972_2.png) [@Javier\_Sancho](https://discourse.threejs.org/u/Javier_Sancho)\
**Post date:** [June 14, 2019, 2:45pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/19 "2019-06-14T14:45:08Z")

</div>

Im using Windows and Chrome.

Despite of the OS, on client side I was able to load the STL file with no problems, the errors have come when putting the Vue framework and trying to load the STL file from server side. I know that the file has no problems at all as I have been able to load it, but the problem is that changing to Vue it stopped working, and is not that Vue and Three are incompatible, because the Scene, Renderer, Lights, etc. are being loaded in a proper way.

Creating a Vue instance, putting the code needed to load the STL file and running `npm run dev` to start the server, and the STL file does not load, STLLoader.js stops at face 20, vertice 2 with the error I put before.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 14, 2019, 2:58pm UTC](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068/20 "2019-06-14T14:58:14Z")

</div>

I’m not familiar with Vue but have you tried the [mentioned solution](https://github.com/enspiral-cherubi/three-stl-loader/issues/8#issuecomment-403470131) from the github issue?

[Next page](https://discourse.threejs.org/t/stlloader-in-vue-js-error/8068.md?page=2)
