Nutlope / aicommits

A CLI that writes your git commit messages for you with AI
https://www.npmjs.com/package/aicommits
MIT License
7.93k stars 379 forks source link

Syntax Error #74

Closed kcoderhtml closed 1 year ago

kcoderhtml commented 1 year ago

When I run the command, I get this error. I installed the program through NPM exactly as shown in the README.

file:///usr/local/lib/node_modules/aicommits/dist/cli.mjs:9
`),t=[];for(let c=0;c<Math.max(n.length,i.length);c++)n[c]!==i[c]&&t.push(c);return t}const Vn=Symbol("clack:cancel");function Hn(e){return e===Vn}function Ze(e,a){e.isTTY&&e.setRawMode(a)}const Jr=new Set(["up","down","left","right","space","enter"]);class Gn{constructor({render:a,input:n=sn,output:i=on,...t},c=!0){this._track=!1,this._cursor=0,this.state="initial",this.error="",this.subscribers=new Map,this._prevFrame="",this.opts=t,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=a.bind(this),this._track=c,this.input=n,this.output=i}prompt(){const a=new Ns(0);return a._write=(n,i,t)=>{this._track&&(this.value=this.rl.line.replace(/\t/g,""),this._cursor=this.rl.cursor,this.emit("value",this.value)),t()},this.input.pipe(a),this.rl=un.createInterface({input:this.input,output:a,tabSize:2,prompt:"",escapeCodeTimeout:50}),un.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on("keypress",this.onKeypress),Ze(this.input,!0),this.render(),new Promise((n,i)=>{this.once("submit",()=>{this.output.write(V.cursor.show),Ze(this.input,!1),n(this.value)}),this.once("cancel",()=>{this.output.write(V.cursor.show),Ze(this.input,!1),n(Vn)})})}on(a,n){const i=this.subscribers.get(a)??[];i.push({cb:n}),this.subscribers.set(a,i)}once(a,n){const i=this.subscribers.get(a)??[];i.push({cb:n,once:!0}),this.subscribers.set(a,i)}emit(a,...n){const i=this.subscribers.get(a)??[],t=[];for(const c of i)c.cb(...n),c.once&&t.push(()=>i.splice(i.indexOf(c),1));for(const c of t)c()}unsubscribe(){this.subscribers.clear()}onKeypress(a,n){if(this.state==="error"&&(this.state="active"),n?.name&&Jr.has(n.name)&&this.emit("cursor",n.name),a&&(a.toLowerCase()==="y"||a.toLowerCase()==="n")&&this.emit("confirm",a.toLowerCase()==="y"),n?.name==="return"){if("placeholder"in this.opts&&!this.value&&(this.value=this.opts.placeholder),this.opts.validate){const i=this.opts.validate(this.value);i&&(this.error=i,this.state="error",this.rl.write(this.value))}this.state!=="error"&&(this.state="submit")}a===""&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`

SyntaxError: Unexpected token '?'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18)
    at async link (internal/modules/esm/module_job.js:42:21)
kcoderhtml commented 1 year ago

Seems to be related to this line https://github.com/Nutlope/aicommits/blob/68fc8ad736e38a9497e94236800d32c9264576d7/src/cli.ts#L9

kcoderhtml commented 1 year ago

According to Stack Overflow using const pj = require('./package.json') at https://github.com/Nutlope/aicommits/blob/68fc8ad736e38a9497e94236800d32c9264576d7/src/cli.ts#L9 pj.version at https://github.com/Nutlope/aicommits/blob/68fc8ad736e38a9497e94236800d32c9264576d7/src/cli.ts#L21 and pj.description at https://github.com/Nutlope/aicommits/blob/68fc8ad736e38a9497e94236800d32c9264576d7/src/cli.ts#L33 might solve the problem.

privatenumber commented 1 year ago

If it's a Syntax error I'm guessing it's your Node.js version.

Can you share reproduction details?

kcoderhtml commented 1 year ago

npm --version says 8.5.1

privatenumber commented 1 year ago

You can get the Node.js version like this: node -v

FazarSN commented 1 year ago

I get this error too, my node version is v12.22.9

privatenumber commented 1 year ago

@FazarSN

Node v12 reached end-of-life in 2022-04-30.

Please use the current LTS (v14~18).

FazarSN commented 1 year ago

update to v18.14.1 and its fixed. thank you

privatenumber commented 1 year ago

I think this can be closed but as an action item, we should specify which version of Node.js is required in the README.

kcoderhtml commented 1 year ago

Thanks for your help!