'Installing troika-three-text from npm not working?

I need to add some texts to a scene in three-js and I've seen Troika seems to be perfect for it. The problem is that when I install troika, I can't find a way to call the module, and/or it has problems with references... I don't seem to find anything related anywhere, people ask questions like they simply install troika and voi-la, and for me it's been complicated

so I have three running perfectly, then I install troika (npm install troika-three-text)

it generates some folders in the node_modules folder, now the instalation tells you that you have to call it using

import { Text } from 'troika-three-text',

when I do this, I get this message:

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

so then I try with:

import { Text } from '../node_modules/troika-three-text/dist/troika-three-text.esm.js'

and now the problem is the following...

'Failed to resolve module specifier "troika-worker-utils". Relative references must start with either "/", "./", or "../".'

So I don't know what to do, either I have to manually change every path inside the scripts of all the troika folders, or what? it doesn't make any sense, please someone help me U_U thank you!!!



Solution 1:[1]

I just ran into this problem as well while playing, with troika.

This may not be a perfect solution,but it's a good workaround because I use three.js in the browser, not in nodejs. My main script is loaded in the index.html file using type="module" and also in the index.html file is an "import map" that uses defines the necessary names as follows:

<html>
  <head>

    <script type="importmap">
      {
      "imports" : {
          "three": "http://unpkg.com/three@latest/build/three.module.js",
          "troika-three-text": "http://unpkg.com/troika-three-text@latest/dist/troika-three-text.esm.js",
          "troika-three-utils": "http://unpkg.com/troika-three-utils@latest/dist/troika-three-utils.esm.js",
          "troika-worker-utils": "http://unpkg.com/troika-worker-utils@latest/dist/troika-worker-utils.esm.js",
           ...
      }
      }
    </script>

Note that I'm getting these files from the unpkg.com CDN. You may have to do something a bit different.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Poynter