webpack: resolve.fallback and resolve.alias do not work with `node:` prefix

Bug report

resolve.fallback and resolve.alias do not work with node: prefix

What is the current behavior?

Module build failed: UnhandledSchemeError: Reading from "node:fs" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.

If the current behavior is a bug, please provide the steps to reproduce.

webpack.config.js

module.exports = {
    mode: "development",
    target: "web",
    entry: "./entry.js",
    resolve: {
      fallback: {
        path: false,
        'node:path': false,
      },
      alias: { 
        path: false,
        'node:path': false,
      }
    }
};

entry.js

import * as mod from "node:fs";

console.log(mod);

What is the expected behavior?

fallback and aliases should work

Other relevant information: webpack version: 5.52.0 Node.js version: any Operating System: any Additional tools: any

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 26
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

on webpack@6 board…

as I understand it should work this way

externals: {
     'node:fs': 'commonjs2 node:fs'
}

I checked it works with configuration above

@alexander-akait can we close this?

@vankop Like we do with require('fs') for web target and allow to ignore import("node:fs") using resolve.alias/resolve.fallback options

@vankop is additional esoteric configuration really the solution here? Can this be handled internally? Does that match the expected result of "node:fs": false?

browser doesn’t have node: schema (i.e. Node.js modules), so for web target it is not possible

Since this isn’t already supported, wouldn’t it be easier to support node: also for target: "web"? From what I understand webpack already supports it for target: "node"