Giter Club home page Giter Club logo

Comments (3)

spgyip avatar spgyip commented on July 17, 2024

The nodejs warning problem

The nodejs warning problem is caused by the dependent package winston. This is my dependent tree

░▒▓    ~/node_modules ▓▒░ npm list winston                                                                                                  ░▒▓ ✔  base   at 18:46:00  ▓▒░
supergui@ /Users/supergui
└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected]

It can be simply verified by require the package with node.

# Add `--trace-warnings` to trace warning stack
node --trace-warnings
> require("winston")
> (node:77783) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:887:11)
    at Object.get (node:internal/modules/cjs/loader:903:5)
    at exports.setLevels (/Users/supergui/node_modules/winston/lib/winston/common.js:35:14)
    at Object.<anonymous> (/Users/supergui/node_modules/winston/lib/winston.js:84:8)
    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)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)

The trace warning are helpful to retrieve the problem is caused by winston.js:84:8.

This problem is solved with the latest 2.x version of winston, we can install a [email protected] then verify it

░▒▓    ~/node_modules ▓▒░ npm install [email protected]                                                                                           ░▒▓ ✔  base   at 18:52:16  ▓▒░

added 1 package, removed 25 packages, changed 2 packages, and audited 218 packages in 692ms

Now we can see the winston is at version 2.4.7

░▒▓    ~/node_modules ▓▒░ npm list                                                                                                          ░▒▓ ✔  base   at 18:52:30  ▓▒░
supergui@ /Users/supergui
├── [email protected]
└── [email protected]

The warning message is gone now

░▒▓    ~/node_modules ▓▒░ node --trace-warnings                                                                                             ░▒▓ ✔  base   at 18:52:32  ▓▒░
Welcome to Node.js v20.11.0.
Type ".help" for more information.
> require("winston")

Fix leetcode-cli

So, we can fix the leetcode's dependencies manually. We use npm-check-updates to help upgrading package.json, we must install the tool first.

# Install ncu
npm i -g npm-check-updates
# Update all dependencies to latest minor version
# This will update the `[email protected]` to `[email protected]`
ncu -u
# Install all packages
npm install
# `winston` is indirect dependency.
# Must install the latest 2.x version of winston manually.
npm install [email protected]

from leetcode-cli.

spgyip avatar spgyip commented on July 17, 2024

Without the warning message, however, the leetcode-cli's show ID problem is not fixed still.

░▒▓    ~/node_modules/leetcode-cli ▓▒░ leetcode show 1                                                                                      ░▒▓ ✔  base   at 19:13:06  ▓▒░
[ERROR] Problem not found!

from leetcode-cli.

spgyip avatar spgyip commented on July 17, 2024

Got the problem, maybe I will raise a PR to fix this.

lib/core.js#L90C6-L90C6

keyword = Number(keyword) || keyword;
const problem = problems.find(function(x) {
      return x.fid === keyword || x.name === keyword || x.slug === keyword;
});

As shown, the type of x.fid is actually String, when querying by ID, unfortunately the keyword is converted to type Number. This will make x.fid === keyword be false.

{
    state: 'None',
    id: 1981,
    fid: '1831',
    name: 'Maximum Transaction Each Day',
    slug: 'maximum-transaction-each-day',
    link: 'https://leetcode.cn/problems/maximum-transaction-each-day/description/',
    locked: true,
    percent: 76.16959064327486,
    level: 'Medium',
    starred: false,
    category: 'database'
}

from leetcode-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.