Thursday, 1 June 2017

Import javascript in html with npm

I am trying to add this github component to my project. I followed the instruction to use npm

npm install pikaday --save

and the pikaday and moment modules are in the node module folder, but when I run my html file:

<body>
<input type="text" id="datepicker" value="9 Jun 2016">
<script src="pikaday.js"></script>
<script src="moment.js"></script>
<script>
    var Pikaday = require('pikaday')
    var picker = new Pikaday({
        field: document.getElementById('datepicker'),
        format: 'D MMM YYYY',
        onSelect: function() {
            console.log(this.getMoment().format('Do MMMM YYYY'));
        }
    });
</script>
</body>

I got the following error:

GET http://localhost:3000/pikaday.js 
(index):14 GET http://localhost:3000/moment.js 
(index):17 Uncaught ReferenceError: Pikaday is not defined
    at (index):17

I change the path to

<script src="/node_modules/pikaday/pikaday.js"></script>

but got the same error



via Deidara

No comments:

Post a Comment