Import issue in the package unist-builder in ES6 codebase
khushal87 opened this issue · 7 comments
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Affected packages and versions: unist-builder 3.0.0
Steps to reproduce
- Imported the package into the project using ES6 and typescript.
- Imported the
ufrom the package. - Received the importing error.
Expected behavior
Should run without any issue, but throws import issues.
Actual behavior
Throwing errors after import.
Errror
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/khushal87/Projects/RNE-AutoGen/node_modules/unist-builder/index.js
require() of ES modules is not supported.
require() of /home/khushal87/Projects/RNE-AutoGen/node_modules/unist-builder/index.js from /home/khushal87/Projects/RNE-AutoGen/json-to-markdown/mdast/templates.ts 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 /home/khushal87/Projects/RNE-AutoGen/node_modules/unist-builder/package.json.
Fix
- Remove
type: "module"from package.json. - Export
uas module.exports = {u};
Note
The above fix works after doing the following changes in the package code under node_modules. So it will be great if this package adapts the new code so that the issue could be resolved.
The use of ESM is intended unifiedjs/unified#121
There is also some discussion of how to migrate to ESM there, there are also more resources at https://blog.sindresorhus.com/get-ready-for-esm-aa53530b3f77 and https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-move-my-commonjs-project-to-esm
Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.
Hi team! I don’t know what’s up as there’s no phase label. Please add one so I know where it’s at.
Thanks,
— bb
Hi team! Could you describe why this has been marked as wontfix?
Thanks,
— bb
@ChristianMurphy When is the next version coming up as in unifiedjs/unified#121?
It's in progress, there are 300+ packages in unified.
unist-builder has it today, is there a specific package you're interested in?
@ChristianMurphy unist-builder, is the one for which I need the fix. Thanks for the reply 🙌