-
Notifications
You must be signed in to change notification settings - Fork 196
Open
Description
Hi, while I am tracing down an issue from react-dev-utils/ModuleScopePlugin, I found that line 37 in RootsPlugin is causing different behavior between linux and windows as it only check for the /
path separator:
enhanced-resolve/lib/RootsPlugin.js
Lines 34 to 42 in d1a3cb6
.tapAsync("RootsPlugin", (request, resolveContext, callback) => { | |
const req = request.request; | |
if (!req) return callback(); | |
if (!req.startsWith("/")) return callback(); | |
forEachBail( | |
this.roots, | |
(root, callback) => { | |
const path = resolver.join(root, req.slice(1)); |
Also I am curious about when the request path is an absolute path starting with '/', why we want to trim off the '/' and treat it as a relative path and concatenate it with another root path?
---- A simple setup to repro the issue
- Follow https://webpack.js.org/guides/getting-started/ to setup a simple env of webpack
- in index.js add some code using crypto like
import crypto from "crypto";
console.log(crypto.createHash("sha256").digest("hex"));
- Add a webpack.config.js with content
const path = require('path');
const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin");
module.exports = {
entry: './src/index.js',
resolve:{
fallback:{
crypto:require.resolve("crypto-browserify"),
buffer:require.resolve("buffer"),
stream: require.resolve("stream-browserify")
},
plugins: [
new ModuleScopePlugin(path.resolve(__dirname, "./src"))
],
},
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
}
};
- Build by running
npx webpack
Then I am seeing
**ERROR** in ./src/index.js 2:0-28
Module not found: Error: You attempted to import /home/brchen/repos/webpack-test/node_modules/crypto-browserify/index.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
UncleJart
Metadata
Metadata
Assignees
Labels
No labels