-
Notifications
You must be signed in to change notification settings - Fork 70
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 find module ESM and Commands not loading properly #321
Comments
@yordis To answer your first question. The extension is mandatory when loading an ES module with import. The second issue may be related to oclif not loading the config from the proper directory. Try passing the absolute path of your project's directory as the second parameter to
|
@rpastro let me try, also, why is that required in this particular case? I cant find information about it |
Passing the absolute path works ... but how would that work once I publish the package then? I am confused about what is going on and what is the proper fix. Do you have some documentation or implementation references? |
@yordis See https://nodejs.org/docs/latest-v16.x/api/esm.html#mandatory-file-extensions |
@yordis Since there is no __dirname in ES modules, you can get the directory where your source file is located as follows:
Once you have the __dirname you can then adjust it to determine the base path of your project. |
Again apologies since I haven't worked on any Oclif / ESM aspects since ~May in my own projects using the new ESM functionality I helped add to Oclif. I gather the documentation was not created by the Oclif team yet. Check out how you can bootstrap things w/ ESM depending on your Node version: Depending on Node version you can do the following (Node 12.20+ or 14.13+):
or for CJS interop for named exports on Node 12.17+ / 14.0+:
The above is for Also as of last time I checked the rest of the Oclif infrastructure wasn't updated for deployment of ESM CLIs, so this may still be the case and demo instructions are here. Requires a custom build of Oclif config v1 adding ESM support for the old dev CLI publishing step. This likely could be out of date as I don't have visibility into the current state of Oclif v2 / development progress since ~May and the additional upgrades to the dev CLI publishing step: |
I am gonna close this folks, I went back to the old version. Until the official website, and official samples are not in ESM I will probably wait for things to be settled a bit. Thank you regardless, you actually helped me to understand the problems ahead. |
Hey folks, I have the following setup, https://github.com/straw-hat-team/cli/tree/master/packages/cli which I am trying to convert to ESM
But I keep getting the following:
I fixed this by adding the extension to the import (is that required now?)
But then the commands don't seem to be working properly
Any idea of what the proper setup suppose to be for an ESM project? I can't find an example project of it.
Thanks in advanced,
The text was updated successfully, but these errors were encountered: