Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dateformat not working with "require" ? #176

Open
thomas-topway-it opened this issue Nov 14, 2021 · 8 comments · May be fixed by #183
Open

dateformat not working with "require" ? #176

thomas-topway-it opened this issue Nov 14, 2021 · 8 comments · May be fixed by #183

Comments

@thomas-topway-it
Copy link

using import I get this error
SyntaxError: Cannot use import statement outside a module
while using require this error

Error [ERR_REQUIRE_ESM]: require() of ES Module /var/www/html/wikisphere-nodejs/node_modules/dateformat/lib/dateformat.js from /var/www/html/wikisphere-nodejs/fetch.js not supported.
Instead change the require of dateformat.js in /var/www/html/wikisphere-nodejs/fetch.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/var/www/html/wikisphere-nodejs/fetch.js:30:18) {
  code: 'ERR_REQUIRE_ESM'

any hint ?

(node v16.13.0
npm 8.1.0)

@jgravois
Copy link

the article below does a pretty good job of explaining options for consuming ES Modules from within CommonJS.

https://regbrain.com/article/how-to-run-es-packages-in-commonjs-modules

TL;DR, you can:

  1. keep old versions of dependencies
  2. move entire application to ES
  3. tactically integrate ES modules into CommonJS code

@Kozenomenon
Copy link

Been using this for years. Disappointing change. Not seeing how this benefits things at all.

I do not need to async load my date formatter. I'm gonna toss that in a const and ref it where I need to when I need to. Like at the start of the process. Once. Its already gonna be on disk. I'm not waiting for some http call to get it.

Why would I go through these hoops just to 'use ES modules ooohh aaahhh' like some kind of epeen stroke...

Moving on to some other date formatter that does not require annoying hoops to use.

(I never go and comment like this- that's how stupid I think this change was.)

@jgravois
Copy link

@Kozenomenon thank you for taking the time to let us all know how you feel.

@matushorvath
Copy link

I am now unable to import a module that uses dateformat from a Jest test, because Jest support for ES6 modules is still experimental and requires even more hoops to jump through. Thank you for providing this package, I would love to keep using it, but finding an alternative that keeps working with current versions of the tools we use is currently more acceptable than switching the whole project to an experimental mode of a critical UT framework we use.

tl;dr While I applaud your effort to support ES6, which is the future, it's still too early to completely drop CommonJS support.

@chase-manning
Copy link
Collaborator

I am now unable to import a module that uses dateformat from a Jest test, because Jest support for ES6 modules is still experimental and requires even more hoops to jump through. Thank you for providing this package, I would love to keep using it, but finding an alternative that keeps working with current versions of the tools we use is currently more acceptable than switching the whole project to an experimental mode of a critical UT framework we use.

tl;dr While I applaud your effort to support ES6, which is the future, it's still too early to completely drop CommonJS support.

@matushorvath Thanks so much for the feedback! If you have any suggestions for how we could improve, please feel free to raise a PR! 😄

@pravi pravi linked a pull request May 12, 2022 that will close this issue
@pravi
Copy link

pravi commented May 12, 2022

@chase-manning I have opened #183 to add support for cjs

@jamesstojan1
Copy link

Been using this for years. Disappointing change. Not seeing how this benefits things at all.

I do not need to async load my date formatter. I'm gonna toss that in a const and ref it where I need to when I need to. Like at the start of the process. Once. Its already gonna be on disk. I'm not waiting for some http call to get it.

Why would I go through these hoops just to 'use ES modules ooohh aaahhh' like some kind of epeen stroke...

Moving on to some other date formatter that does not require annoying hoops to use.

(I never go and comment like this- that's how stupid I think this change was.)

I 100% agree this is a rather annoying change and doesn't seem to create any value.

@cryptomaxsun
Copy link

I encountered the same problem. How can this be fixed?
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/max/pool/node_modules/dateformat/lib/dateformat.js from /home/max/pool/lib/logger.js not supported.Instead change the require of dateformat.js in /home/max/pool/lib/logger.js to a dynamic import() which is available in all CommonJS modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants