Node_module 'dateformat' - Unable to 'import' or 'require' the module

I installed the ‘dateformat’ npm module but am unable to import it into my code.

The Github ‘dateformat’ documentation says to import using:

var dateFormat = require('dateformat');

… but Corvid doesn’t seem to support the “require” function.

Both

import dateFormat from 'dateformat'
import dateformat from 'dateformat'

give me the same error:

  • Cannot find module ‘dateformat’ in ‘public/pages/dqqdc.js’

I am trying to call a function like this from the node_module dateformat module:

$item("#textCloseTime").text = dateFormat(itemData.bidCloseDateTime,"longTime")

which should work according to the Github documentation.

  • How do I import the module into Wix?

  • How do I call it?

Thanks in advance!

Although the require statement is flagged as an error, it in fact works. I use the require statement myself.

note that currently importing npm modules is only supported in backend files. Move the import to the backend and it should work.

Thanks for the prompt replies.

Now that I re-read the documentation, it does say the npm modules are only for the backend code .

Since these are date formatting manipulations, for performance it makes sense to use other frontend formatting options rather than a backend call.

I would be nice if the npm package manager lightbox said clearly that

NPM MODULES ONLY WORK IN BACKEND CODE

rather than being noted obscurely in the documentation. It would’ve saved me a few hours.

I passed your request on to the docs team.

@toddcherron note that you can now use npm packages in your front-end page code, check out this for more info:
https://www.wix.com/corvid/forum/corvid-tips-and-updates/you-can-now-officially-use-npm-packages-in-your-front-end-page-code