three.interaction.js icon indicating copy to clipboard operation
three.interaction.js copied to clipboard

ES6 directly into Browser

Open psytron opened this issue 4 years ago • 3 comments

Your lib is fantastic and really powerful.

We are loading ES6 directly into modern browsers for optimized loading with Import promise etc. Noticing that three.interaction causes error when used directly.

Example:

<script type="module">     
    import * as THREE from "./node_modules/three/build/three.module.js";
    import { Interaction } from "./node_modules/three.interaction/build/three.interaction.module.js";
</script>

Produces error:

Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

As incremental loading becomes more popular with new browser import Promise, bundle based approach will become less appealing.

Any thoughts?
Is there a way to use /three.interaction.module.js directly in a browser ? Perhaps a version on https://www.unpkg.com/ ? Maybe there is a way to update / extend to work with bundlers and directly at the same time?

psytron avatar Jul 27 '20 01:07 psytron

do you import three before you use three.interaction

jasonChen1982 avatar Jul 28 '20 01:07 jasonChen1982

Having same problem here.

Example:

<script type="module">     
    import * as THREE from "./node_modules/three/build/three.module.js";
    import { Interaction } from "./node_modules/three.interaction/build/three.interaction.module.js";
</script>

Produces error:

Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

As incremental loading becomes more popular with new browser import Promise, bundle based approach will become less appealing.

c4b4d4 avatar Aug 14 '20 23:08 c4b4d4

I was having the same issue. The error is not your import, but rather the importing of THREE inside of three.interaction.module.js, hence the Failed to resolve module specifier. Depending on how your node_modules is setup, you simply have to change the import (1st line) inside of that file to:

import { EventDispatcher, Object3D, Raycaster, Vector2 } from '../../three/build/three.module.js';

I would not recommend this as a long term solution - however. Versions change, and it'll likely get overwritten.

adamf59 avatar Feb 11 '21 07:02 adamf59