0

I want to use the typewriter npm package but I don't understand the example code:

It says... just do npm install, and then do:

import Typewriter from 'typewriter-effect/dist/core';

new Typewriter('#typewriter', {
  strings: ['Hello', 'World'],
  autoStart: true,
});

I usually use whatever = require('whatever'); when using stuff loaded via npm.

Why is it different in this case and how can I use it?

As far as I know, npm installed stuff gets into a folder inside node_modules. So, why would I move it into the dist folder?

Thanks!

  • you've got this backwards: the `dist` folder is *inside* the `typewriter-effect` folder (which is inside `node_modules`), not the other way around. – Esther Aug 16 '22 at 14:05
  • @Esther Thanks for your help. So, I have to explicitly load it from the node_modules folder (node_modules/typewriter-effect/dist/core). But then, why do other packages just do import('whatever') and it already knows where to find it? – Javier Guil Bozal Aug 16 '22 at 14:08
  • why do you have to explicitly load it from the node_modules folder? I'm pretty sure that happens "automatically", were you having issues? – Esther Aug 16 '22 at 14:12
  • @Esther well, that's really weird. It just works. But how does the import statement know it has to look into node modules? – Javier Guil Bozal Aug 16 '22 at 14:25
  • NodeJS knows to look there for modules, see https://stackoverflow.com/questions/63294260/what-is-the-purpose-of-the-node-modules-folder – Esther Aug 16 '22 at 14:31
  • @Esther Thanks, that's really interesting! – Javier Guil Bozal Aug 16 '22 at 16:01

0 Answers0