opencc-js icon indicating copy to clipboard operation
opencc-js copied to clipboard

fix type error

Open aqzhyi opened this issue 3 years ago • 3 comments

webpack-internal:///./node_modules/opencc-js/bundle-node.js:97
      const n = s.length, arr = [];
                  ^

TypeError: Cannot read properties of undefined (reading 'length')
    at Trie.convert (webpack-internal:///./node_modules/opencc-js/bundle-node.js:97:19)
    at convert (webpack-internal:///./node_modules/opencc-js/bundle-node.js:170:48)
    at pushRssToChannel (webpack-internal:///./src/news/pushRssToChannel.ts:31:39)
    at eval (webpack-internal:///./src/bot/botStart.ts:51:52)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[nodemon] app crashed - waiting for file changes before starting...

aqzhyi avatar Dec 04 '21 17:12 aqzhyi

s is expected to be a string. For this issue, we should fix the caller instead of modifying this function

Hi, greetings, what do you mean? Which caller?

Do you mean I should fix it on my application itself and not this package?

I tried several ways but I can't fix it unless modifying this package.

import * as OpenCC from 'opencc-js'

export const toTW = OpenCC.Converter({ from: 'cn', to: 'tw' })

It builds ok, but broke after running npm start

Or maybe, what is your suggestions for updating the pull request?

aqzhyi avatar Dec 27 '21 02:12 aqzhyi

Hi, @Aqzhyi. I have just checked and I can run your code without any errors.

import * as OpenCC from 'opencc-js';
const toTW = OpenCC.Converter({ from: 'cn', to: 'tw' });
console.log(toTW('吃面'));  // 吃麵

ayaka14732 avatar Dec 27 '21 03:12 ayaka14732

ok, thank you many thanks, let me do more trials.

failed on Linode and netlify. but local looks working.

screenshot-xKae9cWU

aqzhyi avatar Dec 27 '21 06:12 aqzhyi