Comments (7)
@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 oclif.run
.
oclif.run(process.argv.slice(2), <project path>).then(flush).catch(handle);
from core.
@rpastro let me try, also, why is that required in this particular case? I cant find information about it
from core.
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?
from core.
@rpastro let me try, also, why is that required in this particular case? I cant find information about it
@yordis See https://nodejs.org/docs/latest-v16.x/api/esm.html#mandatory-file-extensions
from core.
@yordis Since there is no __dirname in ES modules, you can get the directory where your source file is located as follows:
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Once you have the __dirname you can then adjust it to determine the base path of your project.
from core.
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:
https://github.com/typhonjs-oclif-scratch/test-cli-modern
https://github.com/typhonjs-oclif-scratch/test-cli-cjs-interop
Depending on Node version you can do the following (Node 12.20+ or 14.13+):
#!/usr/bin/env node
import { run, flush, Errors } from '@oclif/core';
run(void 0, import.meta.url)
.then(flush)
.catch(Errors.handle);
or for CJS interop for named exports on Node 12.17+ / 14.0+:
#!/usr/bin/env node
import oclif from '@oclif/core';
oclif.run(void 0, import.meta.url)
.then(oclif.flush)
.catch(oclif.Errors.handle);
The above is for ./bin/run.js
.
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:
#130 (comment)
from core.
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.
from core.
Related Issues (20)
- topicSeparator space generates wrong message when used alongside usage HOT 1
- Upgrading to a version after 3.20.0 causes issues with hooks HOT 3
- (help): show arg/flag options if user didn't provide any HOT 1
- Command summary displays as topic summary when nested below topic without summary. HOT 1
- FYI: Reduced holiday hours
- tsconfck module cannot be found HOT 2
- Errors on command load should throw errors instead of invalidating the command HOT 6
- SimpleAction does not write newline for status change HOT 7
- [BUG]The issue of ux.prompt handling special characters. HOT 3
- Can't run development mode with bun HOT 2
- RangeError on ux.table when column starts with emoji HOT 1
- ux.Table: Incorrect parsing of double quotes when exporting to CSV HOT 3
- ux.table `maxWidth` column option HOT 2
- CliUx.ux.prompt text truncation HOT 3
- Build failure with `exactOptionalPropertyTypes` enabled HOT 5
- [Feature request] Alias a single flag to a set of multiple flags HOT 1
- Getting MaxListenersExceededWarning: Possible EventEmitter memory leak detected. after updating to latest version of oclif HOT 2
- Error bundling @oclif/core into my project HOT 15
- UX tables get displayed along with json output on usage of --json flag HOT 2
- Specify different oclif options for dev and run HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.