Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field #1465

Closed
marcbachmann opened this issue May 11, 2021 · 10 comments

Comments

@marcbachmann
Copy link

marcbachmann commented May 11, 2021

Node 16 logs a deprecation warning that the syntax for the exports declaration in the package.json changed from "./": "./" to "./*": "./*" .

(node:97520) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /Users/marcbachmann/Development/livingdocsIO/livingdocs-server/master/node_modules/@elastic/elasticsearch7/package.json.
Update this package.json to use a subpath pattern like "./*".
    at emitFolderMapDeprecation (node:internal/modules/esm/resolve:69:11)
    at packageExportsResolve (node:internal/modules/esm/resolve:542:7)
    at resolveExports (node:internal/modules/cjs/loader:477:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:517:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:926:27)

Node 12 doesn't support this new declaration and therefore this would be a breaking change.
How can we get rid of the deprecation warning for newer environments without breaking support for older versions?

@stale
Copy link

stale bot commented Jun 11, 2021

We understand that this might be important for you, but this issue has been automatically marked as stale because it has not had recent activity either from our end or yours.
It will be closed if no further activity occurs, please write a comment if you would like to keep this going.

Note: in the past months we have built a new client, that has just landed in master. If you want to open an issue or a pr for the legacy client, you should do that in https://github.com/elastic/elasticsearch-js-legacy

@stale stale bot added the stale label Jun 11, 2021
@marcbachmann
Copy link
Author

To not do a breaking change, could we expose a separate package.json with the correct annotation in a subdirectory to get rid of the deprecation message?

@stale stale bot removed the stale label Jun 20, 2021
@tony
Copy link

tony commented Jul 11, 2021

I am getting this on node v16.4.0 with @elastic/[email protected]

@tony
Copy link

tony commented Jul 11, 2021

same issue with other projects: postcss/postcss#1455, microsoft/playwright#6248, microsoft/tslib#135 (comment)

@tony
Copy link

tony commented Jul 11, 2021

My workaround was NODE_OPTIONS="--no-deprecation"

e. g.

  • env NODE_OPTIONS="--no-deprecation" yarn start
  • env NODE_OPTIONS="--no-deprecation" node ./myscript.js
  • in package.json "scripts":
    "scripts": {
      "start": "cross-env NODE_OPTIONS=\"--no-deprecation\" yarn develop"
    }
    if you dont' use cross-env, replace cross-env -> env

@trentm
Copy link
Member

trentm commented Sep 27, 2021

@delvedor In Node.js nightly build v17.0.0-nightly20210923c7da13c7c4 (per nodejs/node#40121) this will be a runtime exception:

% ~/tmp/node-v17.0.0-nightly20210923c7da13c7c4-darwin-x64/bin/node
Welcome to Node.js v17.0.0-nightly20210923c7da13c7c4.
Type ".help" for more information.
> require('@elastic/elasticsearch/package.json').version
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /Users/trentm/el/apm-agent-nodejs/node_modules/@elastic/elasticsearch/package.json
    at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:416:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:669:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

This change "fixes" that for me:

--- node_modules/@elastic/elasticsearch/package.json.orig	2021-09-27 10:51:30.000000000 -0700
+++ node_modules/@elastic/elasticsearch/package.json	2021-09-27 10:51:36.000000000 -0700
@@ -75,7 +75,7 @@
       "require": "./index.js",
       "import": "./index.mjs"
     },
-    "./": "./"
+    "./*": "./*"
   },
   "homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
   "keywords": [

@marcbachmann
Copy link
Author

a solution to this could be to list all the files explicitly

@trentm
Copy link
Member

trentm commented Sep 27, 2021

Note that I've found a workaround for my use case. With https://github.com/elastic/apm-agent-nodejs/pull/2351/files#diff-4044438594f145ca4e5b9920e844237cce63dd56744a23e3f263456e6a9f7d35R37-R64 I'm avoiding using require('@elastic/elasticsearch/package.json').

I don't know if others had use cases to directly import other parts of this package.

@marcbachmann
Copy link
Author

Oh, exactly my use case. Thanks

delvedor added a commit that referenced this issue Oct 29, 2021
@delvedor delvedor mentioned this issue Oct 29, 2021
delvedor added a commit that referenced this issue Oct 29, 2021
delvedor added a commit that referenced this issue Oct 29, 2021
@delvedor
Copy link
Member

Closed in #1593.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants