Search code examples
node.jscjkpinyin

Errors with the node modulle pinyin


I have a node.js script in which I want to Romanize Chinese characters. There is a node module pinyin. However, when I try it, I get the error:

      throw err;
      ^

Error: Cannot find module '/Users/jmandeville/Documents/omni-devel/node_modules/pinyin/dist/pinyin.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:444:19)
    at Module._findPath (node:internal/modules/cjs/loader:715:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/Users/jmandeville/Documents/omni-devel/test.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32) {
  code: 'MODULE_NOT_FOUND',
  path: '/Users/jmandeville/Documents/omni-devel/node_modules/pinyin/package.json',
  requestPath: 'pinyin'
}

Yes, I did install the module using "npm install pinyin".

I haven't seen that cjklib has a node module.

Note: this is not a general translation app. But it does encounter the occasional Chinese string that it needs to Romanize.


Solution

  • I figured it out. npm install pinyin installed [email protected]. I saw the "alpha", uninstalled it, and tried instead npm install pinyin@3. This worked.