Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138249

I encounter a problem when installing an npm module

$
0
0

here I start in javascript and nodejs / npm / webpack / theme-bootstrap, I encounter a problem when installing an npm module, I do not understand why ... I tried with various packages, so I say it must be a misunderstanding ...


    root/
      ├── .babelrc
      ├── .gitignore
      ├── package.json
      ├── postcss.config.js
      ├── webpack.config.js
      ├── src/
      │   ├── js/
      │   │   ├── modules/
      │   │   ├── vendor/
      │   │   └── app.js
      └── dist/
          └── js/
              └── app.js


1) npm i html-to-text (https://www.npmjs.com/package/html-to-text)
2) npm install
3) import file in app.js

    import "./modules/htmltotext";

4) import module in htmltotext.js (I created this file)

import "html-to-text";
const htmlToText = require('html-to-text');

5) npm run build
6) Start the HTML page with the web server and I encounter an error

error : Uncaught ReferenceError: htmlToText is not defined at localhost/:20

<!DOCTYPE html>
    <html lang="fr">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script src="dist/js/app.js"></script>
    </head>

    <body>
        <div id="root">
            <h1>Hello World</h1>
        </div>
    </body>
    <script>
        const text = htmlToText.fromString('<h1>Hello World</h1>', {
            wordwrap: 130
        });
        console.log(text); // Hello World
        alert(text);
    </script>

    </html>

Do I have to do something else in webpack? or did I miss something else? I watched a lot of tutorials without understanding why it didn't work ... can you help me? thank you


Viewing all articles
Browse latest Browse all 138249

Trending Articles