afc163 / fanyi

A 🇨🇳 and 🇺🇸 translator in your command line
https://npmjs.com/fanyi
MIT License
1.37k stars 130 forks source link

Mac 翻译异常 #98

Closed neochne closed 1 month ago

neochne commented 4 months ago

⠹ node:events:491 throw er; // Unhandled 'error' event ^

TypeError: Assignment to constant variable. at exports.iciba (/usr/local/lib/node_modules/fanyi/lib/print.js:10:11) at /usr/local/lib/node_modules/fanyi/index.js:48:17 at Parser. (/usr/local/lib/node_modules/fanyi/node_modules/xml2js/lib/parser.js:304:18) at Parser.emit (node:events:513:28) at SAXParser.onclosetag (/usr/local/lib/node_modules/fanyi/node_modules/xml2js/lib/parser.js:262:26) at emit (/usr/local/lib/node_modules/fanyi/node_modules/sax/lib/sax.js:625:35) at emitNode (/usr/local/lib/node_modules/fanyi/node_modules/sax/lib/sax.js:630:5) at closeTag (/usr/local/lib/node_modules/fanyi/node_modules/sax/lib/sax.js:890:7) at SAXParser.write (/usr/local/lib/node_modules/fanyi/node_modules/sax/lib/sax.js:1437:13) at exports.Parser.Parser.parseString (/usr/local/lib/node_modules/fanyi/node_modules/xml2js/lib/parser.js:323:31) Emitted 'error' event on Parser instance at: at exports.Parser.Parser.parseString (/usr/local/lib/node_modules/fanyi/node_modules/xml2js/lib/parser.js:327:16) at Parser.parseString (/usr/local/lib/node_modules/fanyi/node_modules/xml2js/lib/parser.js:5:59) at exports.parseString (/usr/local/lib/node_modules/fanyi/node_modules/xml2js/lib/parser.js:369:19) at /usr/local/lib/node_modules/fanyi/index.js:44:9 at done (/usr/local/lib/node_modules/fanyi/node_modules/needle/lib/needle.js:474:14) at PassThrough. (/usr/local/lib/node_modules/fanyi/node_modules/needle/lib/needle.js:734:9) at PassThrough.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.12.1

dosubot[bot] commented 4 months ago

The error "TypeError: Assignment to constant variable" in the fanyi package is caused by attempting to reassign a value to a constant variable, specifically with the chalk module in the iciba function. To fix this, you should change the declaration of chalk from const to let in the lib/print.js file of the fanyi package:

let chalk = require('chalk');

This adjustment allows chalk to be reassigned later in the code without causing an error. You'll need to make this change directly in the source code of the fanyi package on your local machine.

#### Details **Sources** - [lib/print.js](https://github.com/afc163/fanyi/blob/master/lib/print.js) - [bin/fanyi](https://github.com/afc163/fanyi/blob/master/bin/fanyi) - [package.json](https://github.com/afc163/fanyi/blob/master/package.json) - [index.js](https://github.com/afc163/fanyi/blob/master/index.js)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.