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

feat: add node: prefixed modules #12693

Merged
merged 3 commits into from Jun 21, 2021
Merged

Conversation

dnalborczyk
Copy link
Contributor

@dnalborczyk dnalborczyk commented Feb 16, 2021

What kind of change does this PR introduce?

follow-up from: #12181

adds 'node:' prefixed builtin modules.

https://nodejs.org/docs/latest-v12.x/api/esm.html#esm_node_imports

nodejs/node#37246

Did you add tests for your changes?

Does this PR introduce a breaking change?

What needs to be documented once your changes are merged?

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

@alexander-akait
Copy link
Member

Can you add small test?

lib/node/NodeTargetPlugin.js Outdated Show resolved Hide resolved
@sokra
Copy link
Member

sokra commented Feb 16, 2021

make to sure to also add a test case for that.

@webpack-bot
Copy link
Contributor

@dnalborczyk Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@sokra
Copy link
Member

sokra commented Feb 18, 2021

hmm, seems like node: only works in import and not in require, but we always generate require calls for the node.js externals. We need to revisit that when ESM support allows module externals.

@dnalborczyk
Copy link
Contributor Author

dnalborczyk commented Mar 11, 2021

@sokra

hmm, seems like node: only works in import and not in require, but we always generate require calls for the node.js externals.

that's what I tried to explain here: #12181 (comment)

this will be (could be) supported soon in node.js for commonjs modules as well (also mentioned on top of this thread): nodejs/node#37246

We need to revisit that when ESM support allows module externals.

I thought esm support is currently being added to webpack? https://github.com/webpack/webpack/releases/tag/v5.22.0

@alexander-akait
Copy link
Member

@dnalborczyk I think we need wait when it was merged and we can merge it too

@dnalborczyk
Copy link
Contributor Author

@dnalborczyk I think we need wait when it was merged and we can merge it too

@alexander-akait it's merged now. it seems it's being shipped in node v16.x and possibly backported later on.

@sokra
Copy link
Member

sokra commented Mar 26, 2021

Ok node merged node: support for require, so this PR is fine now. A test case is still missing for that.

@karlhorky
Copy link
Contributor

This will close #13290 when merged

@alexander-akait
Copy link
Member

@dnalborczyk friendly ping

@karlhorky
Copy link
Contributor

So this feature is about to get more usage: the node: scheme / prefix / protocol was backported to Node.js 14.13.1 / 12.20.0 🎉

https://nodejs.org/api/esm.html -> link "node: Imports" (links with anchors don't scroll properly right now)

Screen Shot 2021-05-30 at 11 04 39

@karlhorky
Copy link
Contributor

An alternative to the approaches in #13311 and #12693 would be to use is-core-module (which was split from resolve in browserify/resolve@7c26483), so that this list doesn't need to be maintained and tested by webpack itself.

dnalborczyk and others added 3 commits June 18, 2021 11:00
@webpack-bot
Copy link
Contributor

@sokra The most important CI builds failed. This way your PR can't be merged.

Please take a look at the CI results from azure (1 errors / 1 warnings) and appveyor (success) and fix these issues.

@sokra sokra merged commit de5365b into webpack:master Jun 21, 2021
@sokra
Copy link
Member

sokra commented Jun 21, 2021

Thanks

@karlhorky
Copy link
Contributor

Thanks @sokra! Looking forward to using this! (also with our students in Next.js!)

Will this be in a new patch (5.39.2) or minor (5.40.0)?

@alexander-akait
Copy link
Member

@fregante please create steps to reproduce, if you use target: 'web' it is expected, no node:path in browser

@alexander-akait
Copy link
Member

You can use alias and use https://github.com/browserify/path-browserify

@alexander-akait
Copy link
Member

But maybe better to ask developer provide browser based version of library

@alexander-akait
Copy link
Member

The developer does, but it uses exports.browser in the package.json, which doesn't seem to be picked up and I wasn't able to find any issues regarding exports map on this repo either.

It will be used if it is provided

@alexander-akait
Copy link
Member

Give me time, I will investigate

@alexander-akait
Copy link
Member

alexander-akait commented Sep 7, 2021

Because the problem in other place, what is the problem with waiting an answer?

@alexander-akait
Copy link
Member

Change your import on import * as mod from "filenamify/browser";

@alexander-akait
Copy link
Member

@alexander-akait
Copy link
Member

And we cannot analyze it is subpath for browser or not, so you should explicitly use filenamify/browser

@alexander-akait
Copy link
Member

But here other problem resolve.fallback.path/resolve.fallback['node:path'] is not respected

@alexander-akait
Copy link
Member

Issue for resolve.fallback and resolve.alias #14166

@alexander-akait
Copy link
Member

I don't know what we need explain here, Node.js docs describe how exports works

@alexander-akait
Copy link
Member

Where we should docs it?

@alexander-akait
Copy link
Member

Here answer #12693 (comment), exports is just subpath of URL, we can't understand that code for browser or for node or for other env

@alexander-akait
Copy link
Member

exports.browser in package.json is not automatically picked up on web target #14163 is the issue that's missing a solution, and is not linked to this one

And should not do it - ./browser is part of URL, if you need special target change it on browser, i.e.:

{
	"exports": {
		"browser": "./browser.js",
		"default": "./index.js"
	}
}

No ./

@alexander-akait
Copy link
Member

No need discussion, what is the problem? I answered the same multiple times, ./browser will not and should not work as you expected, logic described in Node.js docs

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

Successfully merging this pull request may close these issues.

None yet

5 participants