felixge/node-dateformat

DeprecationWarning re full filename and extension

drmrbrewer opened this issue · 2 comments

I'm getting the following warning when running a node app with the latest version of dateformat:

(node:20) [DEP0151] DeprecationWarning: Package /usr/src/app/node_modules/dateformat/ has a "main" field set to "lib/dateformat", excluding the full filename and extension to the resolved file at "lib/dateformat.js", imported from /usr/src/app/myapp.js.
 Automatic extension resolution of the "main" field is deprecated for ES modules.

It will be solved by changing the following code.

package.json

...
  "license": "MIT",
  "type": "module",
  "main": "lib/dateformat.js",
...

Just specify the full file name and extension as the warning message says.

@rlj1202 indeed, it should be a simple fix (@chase-manning). I believe that the change should go a little further than you suggest, by using the full relative path name including prefix: "main": "./lib/dateformat.js".

Also, I think that main should be replaced by exports (see e.g. here) but I don't understand enough about this to know if there are any unintended consequences of doing this (see e.g. here).