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

Fix CommonJS export #90

Merged
merged 1 commit into from
Feb 7, 2022
Merged

Fix CommonJS export #90

merged 1 commit into from
Feb 7, 2022

Conversation

mypipsen
Copy link
Contributor

@mypipsen mypipsen commented Feb 7, 2022

This small fix addresses the CommonJS error introduced in 591b4e4

Error [ERR_REQUIRE_ESM]: require() of ES Module

combinatorics.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename combinatorics.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Can be tested with the following example:

package.json

{
  "dependencies": {
    "js-combinatorics": "^1.5.5"
  }
}

index.js

const combinatorics = require("js-combinatorics");

console.log(combinatorics.version);

node index.js

@mypipsen mypipsen changed the title Fixed commonjs export Fix CommonJS export Feb 7, 2022
@dankogai dankogai merged commit 200c972 into dankogai:main Feb 7, 2022
@dankogai
Copy link
Owner

dankogai commented Feb 7, 2022

Thank you!

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 this pull request may close these issues.

2 participants