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

Support node:http etc. #303

Open
vjpr opened this issue Sep 16, 2021 · 4 comments
Open

Support node:http etc. #303

vjpr opened this issue Sep 16, 2021 · 4 comments

Comments

@vjpr
Copy link

vjpr commented Sep 16, 2021

https://nodejs.org/api/esm.html#esm_node_imports

Workaround

https://github.com/sindresorhus/is-builtin-module

@alexander-akait
Copy link
Member

We already supports this in webpack, what do you mean?

@vjpr
Copy link
Author

vjpr commented Sep 17, 2021

When using enhanced-resolve, it tries to locate the 'http' package but it should be ignored because it's a built-in. But maybe this is out of scope for this package.

@pauldraper
Copy link

maybe this is out of scope for this package

If require.resolve does it, it's not out of scope.

@scagood
Copy link
Contributor

scagood commented Sep 25, 2024

My solution to this is to use the alias option, with the alias field set to false. This way the resolver just returns false instead of throwing.

This was particularly useful for the usecase in #310 where I could not just check the import before hand!

My alias list is:

const alias = [
  { name: 'assert', alias: false },
  { name: 'assert/strict', alias: false },
  { name: 'async_hooks', alias: false },
  { name: 'buffer', alias: false },
  { name: 'child_process', alias: false },
  { name: 'cluster', alias: false },
  { name: 'console', alias: false },
  { name: 'crypto', alias: false },
  { name: 'dgram', alias: false },
  { name: 'diagnostics_channel', alias: false },
  { name: 'dns', alias: false },
  { name: 'dns/promises', alias: false },
  { name: 'domain', alias: false },
  { name: 'events', alias: false },
  { name: 'fs', alias: false },
  { name: 'fs/promises', alias: false },
  { name: 'http', alias: false },
  { name: 'http2', alias: false },
  { name: 'inspector', alias: false },
  { name: 'inspector/promises', alias: false },
  { name: 'module', alias: false },
  { name: 'net', alias: false },
  { name: 'os', alias: false },
  { name: 'path', alias: false },
  { name: 'path/posix', alias: false },
  { name: 'path/win32', alias: false },
  { name: 'perf_hooks', alias: false },
  { name: 'process', alias: false },
  { name: 'punycode', alias: false },
  { name: 'querystring', alias: false },
  { name: 'readline', alias: false },
  { name: 'readline/promises', alias: false },
  { name: 'repl', alias: false },
  { name: 'stream', alias: false },
  { name: 'stream/consumers', alias: false },
  { name: 'stream/promises', alias: false },
  { name: 'stream/web', alias: false },
  { name: 'string_decoder', alias: false },
  { name: 'timers', alias: false },
  { name: 'timers/promises', alias: false },
  { name: 'tls', alias: false },
  { name: 'trace_events', alias: false },
  { name: 'tty', alias: false },
  { name: 'url', alias: false },
  { name: 'util', alias: false },
  { name: 'util/types', alias: false },
  { name: 'v8', alias: false },
  { name: 'vm', alias: false },
  { name: 'wasi', alias: false },
  { name: 'worker_threads', alias: false },
  { name: 'zlib', alias: false },
  { name: 'node:assert', alias: false },
  { name: 'node:assert/strict', alias: false },
  { name: 'node:async_hooks', alias: false },
  { name: 'node:buffer', alias: false },
  { name: 'node:child_process', alias: false },
  { name: 'node:cluster', alias: false },
  { name: 'node:console', alias: false },
  { name: 'node:crypto', alias: false },
  { name: 'node:dgram', alias: false },
  { name: 'node:diagnostics_channel', alias: false },
  { name: 'node:dns', alias: false },
  { name: 'node:dns/promises', alias: false },
  { name: 'node:events', alias: false },
  { name: 'node:fs', alias: false },
  { name: 'node:fs/promises', alias: false },
  { name: 'node:http', alias: false },
  { name: 'node:http2', alias: false },
  { name: 'node:inspector', alias: false },
  { name: 'node:inspector/promises', alias: false },
  { name: 'node:module', alias: false },
  { name: 'node:net', alias: false },
  { name: 'node:os', alias: false },
  { name: 'node:path', alias: false },
  { name: 'node:path/posix', alias: false },
  { name: 'node:path/win32', alias: false },
  { name: 'node:perf_hooks', alias: false },
  { name: 'node:process', alias: false },
  { name: 'node:querystring', alias: false },
  { name: 'node:readline', alias: false },
  { name: 'node:readline/promises', alias: false },
  { name: 'node:repl', alias: false },
  { name: 'node:sea', alias: false },
  { name: 'node:stream', alias: false },
  { name: 'node:stream/consumers', alias: false },
  { name: 'node:stream/promises', alias: false },
  { name: 'node:stream/web', alias: false },
  { name: 'node:string_decoder', alias: false },
  { name: 'node:test', alias: false },
  { name: 'node:timers', alias: false },
  { name: 'node:timers/promises', alias: false },
  { name: 'node:tls', alias: false },
  { name: 'node:trace_events', alias: false },
  { name: 'node:tty', alias: false },
  { name: 'node:url', alias: false },
  { name: 'node:util', alias: false },
  { name: 'node:util/types', alias: false },
  { name: 'node:v8', alias: false },
  { name: 'node:vm', alias: false },
  { name: 'node:wasi', alias: false },
  { name: 'node:worker_threads', alias: false },
  { name: 'node:zlib', alias: false },
];

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