How do I get rid of this error?
Module not found: Error: You attempted to import /home/sebastian/dev/frontend/node_modules/browserify-zlib/lib/index.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules/.
I was able to get rid of this error by doing sudo FAST_REFRESH=false npm run start:
Module not found: Error: You attempted to import /home/sebastian/dev/frontend/node_modules/react-refresh/runtime.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules/.
My craco.config.js file:
const webpack = require("webpack");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
module.exports = {
webpack: {
configure: (webpackConfig) => {
// Ensure symlinks are disabled for cross-platform compatibility
webpackConfig.resolve.symlinks = false;
webpackConfig.resolve.modules = [
'node_modules',
...(webpackConfig.resolve.modules || []),
];
webpackConfig.resolve.fallback = {
process: require.resolve("process/browser"),
zlib: require.resolve("browserify-zlib"),
util: require.resolve("util"),
buffer: require.resolve("buffer"),
assert: require.resolve("assert"),
path: require.resolve("path-browserify")
};
webpackConfig.plugins.push(
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
process: "process/browser.js",
}),
new NodePolyfillPlugin({
excludeAliases: ['console']
})
);
return webpackConfig;
},
},
};
asked Feb 25, 2025 at 18:13
Sebastian Nielsen
4,2695 gold badges37 silver badges57 bronze badges
lang-js