简体   繁体   中英

Importing and using NPM package

I am trying to use a node module called "tagify" in my node.js app. In the readme file for the package ( https://www.npmjs.com/package/@yaireo/tagify#installation ) it says to setup as follows:

npm i @yaireo/tagify --save

// usage:
import Tagify from '@yaireo/tagify'

var tagify = new Tagify(...)

I ran the npm command and it installed fine. My EJS file has this (not shown is the input name="tags" element):

<script>
    import Tagify from '@yaireo/tagify';

    var input = document.querySelector('input[name=tags]'),
    // init Tagify script on the above inputs
    tagify = new Tagify(input);
</script>

When I load the page, I get this in the console:

Uncaught SyntaxError: Unexpected identifier (reference to 'import' line)

I'm very new to this and very confused. I've been searching the internet for two hours and can't figure out the basic task of getting this package to work. If this questions is redundant, please direct me elsewhere, because I don't know where to go.

<script src="https://cdn.jsdelivr.net/npm/@yaireo/tagify@2.9.7/dist/tagify.min.js"></script>

<script>
    var input = document.querySelector('input[name=tags]'),
    // init Tagify script on the above inputs
    var tagify = new Tagify(input);
</script>

This code is not raw. you need to use technologies like babel or webpack to use it. easy to run this link will be enough

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM