项目运行好好的,然后就报一堆错误
起初我以为我安装了依赖倒置的问题,后来我只输出 hello world 都出错。折腾两晚上。。。还是度娘帮了我
Compiled with problems:X ERROR in ./node_modules/fs-extra/lib/copy/copy-sync.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\copy' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/copy/copy.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\copy' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/empty/index.js 7:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\empty' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/ensure/file.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\ensure' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/ensure/link.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\ensure' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/ensure/symlink-paths.js 3:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\ensure' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/ensure/symlink.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\ensure' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/mkdirs/utils.js 8:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\mkdirs' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/move/move-sync.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\move' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/move/move.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\move' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/output-file/index.js 7:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\output-file' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/remove/rimraf.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\remove' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/remove/rimraf.js 7:15-32 Module not found: Error: Can't resolve 'assert' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\remove' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }' - install 'assert' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "assert": false } ERROR in ./node_modules/fs-extra/lib/util/stat.js 5:13-28 Module not found: Error: Can't resolve 'path' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\util' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } ERROR in ./node_modules/fs-extra/lib/util/stat.js 7:13-28 Module not found: Error: Can't resolve 'util' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\fs-extra\lib\util' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "util": require.resolve("util/") }' - install 'util' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "util": false } ERROR in ./node_modules/graceful-fs/graceful-fs.js 1:9-22 Module not found: Error: Can't resolve 'fs' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\graceful-fs' ERROR in ./node_modules/graceful-fs/graceful-fs.js 9:11-26 Module not found: Error: Can't resolve 'util' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\graceful-fs' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "util": require.resolve("util/") }' - install 'util' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "util": false } ERROR in ./node_modules/graceful-fs/graceful-fs.js 86:6-29 Module not found: Error: Can't resolve 'assert' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\graceful-fs' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }' - install 'assert' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "assert": false } ERROR in ./node_modules/graceful-fs/legacy-streams.js 1:13-37 Module not found: Error: Can't resolve 'stream' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\graceful-fs' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }' - install 'stream-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "stream": false } ERROR in ./node_modules/graceful-fs/polyfills.js 1:16-36 Module not found: Error: Can't resolve 'constants' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\graceful-fs' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "constants": require.resolve("constants-browserify") }' - install 'constants-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "constants": false } ERROR in ./node_modules/jsonfile/index.js 6:8-21 Module not found: Error: Can't resolve 'fs' in 'D:\vueLearning\selfLearningProject\react-lesson\0706\node_modules\jsonfile'
找到react 项目中的webpack.config.js
// 290 行
resolve: { // This allows you to set a fallback for where webpack should look for modules. // We placed these paths second because we want `node_modules` to "win" // if there are any conflicts. This matches Node resolution mechanism. // https://github.com/facebook/create-react-app/issues/253 fallback: { "path": false, "assert": false, "stream": false, "constants": false, "util": false, "fs": false, }, }
完美解决,可以重启成功启动起来
这是因为有些包是Node.js的一部分,但它们在浏览器中不存在。
您需要指出它们或将它们设置为false。
更新您的网页包配置,将出现错误的软件包设置为false:os、dns、crypto、fs、net。或者更好的是,添加所有这些:
ps: https://www.5axxw.com/questions/content/ibfep2#question-recommend
标签:node,resolve,modules,include,报错,path,fallback,copy From: https://www.cnblogs.com/chuanmin/p/16647899.html