dougwilson/nodejs-depd

line info is not help

Closed this issue · 8 comments

egg deprecated ctx.isAjax is deprecated internal/process/next_tick.js:103:7

Hi @atian25 can you provide some more details? I see you're in @eggjs and so I assume you are trying to add this module to that module? Typically when you see a non-useful stack, it's because the following note was missed in the README:

[...] this module uses the calling file to get the boundary for the call stacks, so you should always create a new deprecate object in each file and not within some central file.

I can take a look to see what is happening if you have code I can try, though.

thanks, we use it at https://github.com/eggjs/egg-core/blob/master/lib/egg.js#L156

I'll read the doc again, thanks~

Gotcha. Yea, you cannot use this module in that way in order for the stack traces to make sense. You should always create a new deprecate object in each file you are deprecating items, because that is how the file boundary is determined. If you create it in a single, central file, then the module will latch to that file as the stack boundary and then you'll end up with useless stack traces.

The usage in https://github.com/eggjs/egg-core/blob/1dda9fa9d1d61a1d06913202294ac8690dbef90d/lib/loader/file_loader.js is how the module needs to be loaded: you require('depd')(namespace) at the top of the file and only ever invoke the deprecate function within that same file.

It is not clear to me where you're using the deprecate property in that file you linked to, but the essence is that you cannot centralize the creation of this module like you're doing there.

egg has plugin system, so we define a getter of app.deprecate then plugins and apps can use like this.app.deprecate()

https://github.com/eggjs/egg/blob/984d7320881adf9420e5c7e49d62d5530ad887dd/lib/egg.js#L319

Hi @atian25 thanks. So it's not possible to use this module in that way, as per the readme instructions. For the file https://github.com/eggjs/egg/blob/984d7320881adf9420e5c7e49d62d5530ad887dd/lib/egg.js you need to

  1. Add const deprecate = require('depd')('egg') at the top
  2. Change the line you referenced to deprecate('please use app.config.env instead')

got, thanks for reply timely.

@atian25 no problem :) I happened to be up and about on GitHub 👍