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

[BUG] Node.js 16 results in DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field with file import #6026

Closed
zdm opened this issue Mar 31, 2021 · 29 comments
Assignees

Comments

@zdm
Copy link

zdm commented Mar 31, 2021

Current exports syntax is not compatible with node 15.

(node:12200) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at C:\Users\zdm\.node_modules\playwright-chromium\package.json.
Update this package.json to use a subpath pattern like "./*".

You need to update to the new rules or remove this section.

New rules should looks like this:

"exports": {
    ".": {
      "import": "./index.mjs",
      "require": "./index.js"
    },
    "./*": "./*.js"
  },
@pavelfeldman
Copy link
Member

pavelfeldman commented Mar 31, 2021

Where do you see this message and this line? Could you provide the steps to reproduce? It does not complain on node/15.13 + npm/7.7.6 for me.

@zdm
Copy link
Author

zdm commented Apr 1, 2021

try this code:

require( "playwright-chromium/lib/client/page" );

I need to add custom methods to the Page class prototype, so I need to require client/page directly.
In any case current folders export synax is already deprecated and you need to update it.

@pavelfeldman
Copy link
Member

require( "playwright-chromium/lib/client/page" );

Works for me on the node / npm versions i mentioned above. Are there any steps I can follow to reproduce this?

@zdm
Copy link
Author

zdm commented Apr 1, 2021

You need to perform require from the external script or package.

@pavelfeldman
Copy link
Member

You need to perform require from the external script or package.

That's what I did. Node changed its mind on the deprecation:

nodejs/node#35747
nodejs/node#36859

What is your Node 15 version? Is it recent?

@zdm
Copy link
Author

zdm commented Apr 1, 2021

here is the link to the specification, where this api marked as deprecated.
https://nodejs.org/api/packages.html#packages_subpath_folder_mappings

@zdm
Copy link
Author

zdm commented Apr 1, 2021

my node - 5.13.0

@zdm
Copy link
Author

zdm commented Apr 1, 2021

sorry, 15.13.0 ))

@pavelfeldman
Copy link
Member

I'm on macOS, v15.13.0, I have a single dependency in my node_modules, which is playwright. My index file in the root folder is:

require( "playwright/lib/client/page" );

and I can run it ok. If I add a non-default --pending-deprecation flag I get your warning, but I don't get it without it. Are you by any chance running it with pending deprecations flag?

@pavelfeldman
Copy link
Member

As https://nodejs.org/api/deprecations.html#deprecations_dep0148_folder_mappings_in_exports_trailing states,

Without --pending-deprecation, runtime warnings occur only for exports resolutions not in node_modules.
This means there will not be deprecation warnings for "exports" in dependencies.

Are you using playwright outside of the node_modules?

@zdm
Copy link
Author

zdm commented Apr 1, 2021

adAhh, sorry.
Node was updated today to 15.13.0 and this warning had gone.
It was present on node 15.12.0.

@zdm
Copy link
Author

zdm commented Apr 1, 2021

Yes, i installed playwright globally.

@pavelfeldman
Copy link
Member

Globally is still via node_modules, so we are good. Ok then, closing as not an issue!

@zdm
Copy link
Author

zdm commented Apr 2, 2021

The issue is still present under node 15.13.0.

Way to reproduce:

  1. playwright-chromium installed globally;
  2. node 15.13.0;
const { Page } = require( "playwright-chromium/lib/client/page" );

( async () => {} )();

@mxschmitt
Copy link
Member

I also tried to reproduce, but was not successful in it. As far as I know its required to set the NODE_PATH environment variable to your global node_modules directory, otherwise global imports via require won't work. Did you do this? Also having it reproducible via Docker would be useful and help a lot. Thanks!

@zdm
Copy link
Author

zdm commented Apr 2, 2021

no, I haven't set NODE_PATH, this is not required.
all, what I did to make global modules loadable:

ln -s ~/.npm/lib/node_modules ~/.node_modules

@zdm
Copy link
Author

zdm commented Apr 2, 2021

I think we need to just update exports to the new syntax.
Current style is deprecated and will not work in the next versions.

@mxschmitt
Copy link
Member

Try to set NODE_PATH to your global node_modules (see npm list -g --depth=0 and add there node_modules) folder. Your current approach messes probably some internals up.

@zdm
Copy link
Author

zdm commented Apr 2, 2021

I tested, this not helped.
Could we just update ./ : "./" to ./*: "./*.js" and forget about this?
I checked, new syntax works for the latest and lts node releases.

@pavelfeldman
Copy link
Member

pavelfeldman commented Apr 5, 2021

Since global installs are discouraged, we are unlikely to address it before it becomes a real issue in Node. So far, this deprecation is reversed and I suspect it might vanish altogether because it is hard to change entire npm ecosystem at will. Let's see in what form it makes its way into LTS and revisit it.

@zdm
Copy link
Author

zdm commented Apr 20, 2021

Hi,
In node v16 deprecation warning is shown all the times:

(node:129593) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /mnt/hgfs/projects/devel/crawlsy/node_modules/playwright-core/package.json.
Update this package.json to use a subpath pattern like "./*".

(SEMVER-MAJOR) module: runtime deprecate subpath folder mappings (Antoine du Hamel) #37215
nodejs/node#37215

It's time to update. )

@mxschmitt
Copy link
Member

I was able to reproduce this, since there are no Node.js 16 docker images yet I had to manually install:

docker run -it ubuntu:focal /bin/bash
curl -fsSL https://deb.nodesource.com/setup_16.x | bash 
apt-get install -y nodejs
mkdir test
cd test
npm init -y
npm install playwright-chromium
cat > foo.js <<- EOM
const { Page } = require( "playwright-chromium/lib/client/page" );
EOM
node foo.js

Which results as pointed out in:

(node:3895) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /test/node_modules/playwright-chromium/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)

@mxschmitt mxschmitt reopened this Apr 20, 2021
@mxschmitt mxschmitt changed the title [BUG] Please, update or remove exports section in package.json [BUG] Node.js 16 results in DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field with file import Apr 20, 2021
@dgozman dgozman added P2-bug and removed triaging labels Apr 20, 2021
@mxschmitt
Copy link
Member

Closing for now, nobody reported any issues.

@zdm
Copy link
Author

zdm commented May 11, 2021

This was not fixed!
Your pull request wasn't applied.

@mxschmitt
Copy link
Member

See the comment in the pull request. A lot of package maintainers need to deal with it and the only option to have no warning is to break older node versions.

We are waiting for more users to face into that problem.

@zdm
Copy link
Author

zdm commented May 11, 2021

Did you tested with the old versions?
I tested with the current LTS version - it works.
What is the minimal version that you are want to support?

@mxschmitt
Copy link
Member

See the GitHub Action run on the pull request.

rashfael added a commit to rashfael/tuiv that referenced this issue Jun 20, 2021
@zdm
Copy link
Author

zdm commented Oct 20, 2021

In nodejs v17 current exports not working anymore.

[36e2ffe6dc] - (SEMVER-MAJOR) module: subpath folder mappings EOL (Guy Bedford) #40121
[64287e4d45] - (SEMVER-MAJOR) module: runtime deprecate trailing slash patterns (Guy Bedford) #40117

Could you pls add "./*": "./*" pattern.

@arprinceofficial
Copy link

(node:6112) [DEP0155] DeprecationWarning: Use of deprecated trailing slash pattern mapping "./" in the "exports" field module resolution of the package at D:\Github Projects\emasbd\emasbd_frontend\node_modules\flowbite-vue\package.json imported from D:\Github Projects\emasbd\emasbd_frontend\node_modules. Mapping specifiers ending in "/" is no longer supported.
(Use node --trace-deprecation ... to show where the warning was created)

(node:6112) [DEP0166] DeprecationWarning: Use of deprecated double slash resolving "./dist//index.mjs" for module request ".//index.mjs" matched to "./*" in the "exports" field module resolution of the package at D:\Github Projects\emasbd\emasbd_frontend\node_modules\flowbite-vue\package.json imported from D:\Github Projects\emasbd\emasbd_frontend\node_modules.

pls help me for getting this warning

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

Successfully merging a pull request may close this issue.

5 participants