Cannot import modules installed with NPM
I'm using ES6 import keyword, I have tried this with a various of different packages, but it just doesn't work, for example, I installed a package called moment, by typing npm install moment in my terminal, then I wrote the following code: import moment from 'moment'; let myDate = new Date(); let myCoolDate = moment(myDate).format('LL'); document.body.innerHTML = myCoolDate; This was written inside a scrip tage with the attribute type="module", this however gave me the following error: Uncaught TypeError: Failed to resolve module specifier "dat.gui". Relative references must start with either "/", "./", or "../". So I then tried writing ./moment, hoping that perhaps that may fixed that, but nope, it did not, instead I just got a new error message: GET http://127.0.0.1:56065/moment net::ERR_ABORTED 404 (Not Found) No file called moment exists in my project folder though, only the package.json file, the package-lock.json file, and the node_modules folder, so I don't really understand how this was supposed to work, the instructions say I should just write moment however, so that's what I did, I have never used any packages before so I'm a little confused and if anyone can help it would be really cool.
3/4/2021 7:37:44 AMKarak10
6 AnswersNew Answer
Replace import moment from 'moment' With const moment = require('moment')
To use ES6 import package, you should use webpack to bundle your codes.
Stuvan I will try that
Calviղ what's that?
Calviղ Webpack seems a little complicated to use, can I use parcel instead?