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

Cannot require() starting with version 4 #105

Closed
mdmower opened this issue Nov 13, 2021 · 3 comments
Closed

Cannot require() starting with version 4 #105

mdmower opened this issue Nov 13, 2021 · 3 comments

Comments

@mdmower
Copy link

mdmower commented Nov 13, 2021

Starting with version 4.0.0, it is not possible to import d3-time-format in a script using require() syntax, for example:

const { timeParse, timeFormat } = require('d3-time-format');

The error is:

internal/modules/cjs/loader.js:1102
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/myprogram/node_modules/d3-time-format/src/index.js
require() of ES modules is not supported.
require() of /path/to/myprogram/node_modules/d3-time-format/src/index.js from /path/to/myprogram/myprogram.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /path/to/myprogram/node_modules/d3-time-format/package.json.

Could you restore support for using require(...) syntax instead of requiring import ... syntax? Note that developers can still opt to use import ... syntax if they like, this would just restore support for require(...) which is quite convenient when quickly writing utility scripts.

@mdmower
Copy link
Author

mdmower commented Nov 13, 2021

I'm sorry that you don't see this as an issue and have simply closed it. I'll just provide one article worth reading, paying special attention to section How to Create a Good “Dual Package” Containing Both CJS and ESM: https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1

@mbostock
Copy link
Member

I deliberately dropped support for CJS. I have no interest in maintaining multiple module formats and encourage everyone to adopt ES modules. If you disagree, you are free to fork this module, to use an earlier version, or simply to not use it. Thank you for your feedback.

@mdmower
Copy link
Author

mdmower commented Nov 13, 2021

I understand. I appreciate the response.

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

No branches or pull requests

2 participants