Webpack无法编译简单应用程序

时间:2018-03-02 21:21:23

标签: webpack

我是node和webpack的新手。我正在尝试设置一个简单的应用程序。我无法让webpack成功编译应用程序。几天来,我一直在努力解决这个问题。我的申请位于https://github.com/Weste15/test-app.git。我得到了很多错误。任何帮助将不胜感激。谢谢!

webpack built 7244fa5788b2202d1b0e in 46644ms
✖ 「wdm」: Hash: 7244fa5788b2202d1b0e
Version: webpack 4.0.1
Time: 46644ms
Built at: 2018-3-2 14:36:59
    Asset    Size  Chunks  Chunk Names
bundle.js  11 MiB       0  main
Entrypoint main = bundle.js
   [1] ./node_modules/path-browserify/index.js 6.04 KiB {0} [built]
  [61] (webpack)/buildin/module.js 519 bytes {0} [built]
 [201] ./node_modules/express/index.js 224 bytes {0} [built]
 [363] (webpack)/lib/webpack.js 6.97 KiB {0} [built]
 [416] ./webpack.config.dev.js 530 bytes {0} [built]
 [417] ./routes/users.js 203 bytes {0} [built]
 [418] ./routes/index.js 205 bytes {0} [built]
 [420] (webpack)-hot-middleware/middleware.js 3.57 KiB {0} [built]
[1090] ./app.js 843 bytes {0} [built]
[1091] (webpack)-hot-middleware/process-update.js 4.23 KiB {0} [built]
[1096] (webpack)-hot-middleware/client-overlay.js 2.16 KiB {0} [built]
[1098] ./node_modules/strip-ansi/index.js 161 bytes {0} [built]
[1099] (webpack)-hot-middleware/client.js 7.18 KiB {0} [built]
[1100] (webpack)/hot/dev-server.js 1.66 KiB {0} [built]
[1101] multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js 52 bytes {0} [built]
    + 1087 hidden modules

WARNING in ./node_modules/uglifyjs-webpack-plugin/node_modules/uglify-es/tools/node.js
18:11-32 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/uglifyjs-webpack-plugin/node_modules/uglify-es/tools/node.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/minify.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

WARNING in ./node_modules/loader-runner/lib/loadLoader.js
3:2-28 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/loader-runner/lib/loadLoader.js
 @ ./node_modules/loader-runner/lib/LoaderRunner.js
 @ (webpack)/lib/NormalModule.js
 @ (webpack)/lib/AutomaticPrefetchPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

WARNING in ./node_modules/use/utils.js
3:34-41 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./node_modules/use/utils.js
 @ ./node_modules/use/index.js
 @ ./node_modules/snapdragon/lib/compiler.js
 @ ./node_modules/snapdragon/index.js
 @ ./node_modules/micromatch/lib/utils.js
 @ ./node_modules/micromatch/index.js
 @ (webpack)/lib/optimize/SideEffectsFlagPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

WARNING in ./node_modules/worker-farm/lib/child/index.js
49:33-53 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/worker-farm/lib/child/index.js
 @ ./node_modules/worker-farm/lib/fork.js
 @ ./node_modules/worker-farm/lib/farm.js
 @ ./node_modules/worker-farm/lib/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

WARNING in ./node_modules/express/lib/view.js
79:29-41 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/express/lib/view.js
 @ ./node_modules/express/lib/application.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

WARNING in ./node_modules/chokidar/lib/fsevents-handler.js
Module not found: Error: Can't resolve 'fsevents' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\chokidar\lib'
 @ ./node_modules/chokidar/lib/fsevents-handler.js 7:17-36
 @ ./node_modules/chokidar/index.js
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

WARNING in (webpack)/lib/debug/ProfilingPlugin.js
Module not found: Error: Can't resolve 'inspector' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\webpack\lib\debug'
 @ (webpack)/lib/debug/ProfilingPlugin.js 8:13-33
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

WARNING in ./node_modules/loader-runner/lib/loadLoader.js
System.import() is deprecated and will be removed soon. Use import() instead.
For more info visit https://webpack.js.org/guides/code-splitting/
 @ ./node_modules/loader-runner/lib/LoaderRunner.js 3:2-28 7:17-40
 @ (webpack)/lib/NormalModule.js
 @ (webpack)/lib/AutomaticPrefetchPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

WARNING in configuration
The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment.

ERROR in ./node_modules/worker-farm/lib/fork.js
Module not found: Error: Can't resolve 'child_process' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\worker-farm\lib'
 @ ./node_modules/worker-farm/lib/fork.js 3:21-45
 @ ./node_modules/worker-farm/lib/farm.js
 @ ./node_modules/worker-farm/lib/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/cacache/get.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\cacache'
 @ ./node_modules/cacache/get.js 5:11-24
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/chokidar/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\chokidar'
 @ ./node_modules/chokidar/index.js 3:9-22
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/chokidar/lib/fsevents-handler.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\chokidar\lib'
 @ ./node_modules/chokidar/lib/fsevents-handler.js 3:9-22
 @ ./node_modules/chokidar/index.js
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/chokidar/lib/nodefs-handler.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\chokidar\lib'
 @ ./node_modules/chokidar/lib/nodefs-handler.js 3:9-22
 @ ./node_modules/chokidar/index.js
 @ ./node_modules/watchpack/lib/DirectoryWatcher.js
 @ ./node_modules/watchpack/lib/watcherManager.js
 @ ./node_modules/watchpack/lib/watchpack.js
 @ (webpack)/lib/node/NodeWatchFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/chownr/chownr.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\chownr'
 @ ./node_modules/chownr/chownr.js 4:9-22
 @ ./node_modules/cacache/lib/util/fix-owner.js
 @ ./node_modules/cacache/lib/util/tmp.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/copy-concurrently/copy.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\copy-concurrently'
 @ ./node_modules/copy-concurrently/copy.js 8:13-26
 @ ./node_modules/move-concurrently/move.js
 @ ./node_modules/cacache/lib/util/move-file.js
 @ ./node_modules/cacache/lib/content/write.js
 @ ./node_modules/cacache/put.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/destroy/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\destroy'
 @ ./node_modules/destroy/index.js 14:17-30
 @ ./node_modules/send/index.js
 @ ./node_modules/express/lib/response.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/etag/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\etag'
 @ ./node_modules/etag/index.js 22:12-25
 @ ./node_modules/express/lib/utils.js
 @ ./node_modules/express/lib/response.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/express/lib/view.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\express\lib'
 @ ./node_modules/express/lib/view.js 18:9-22
 @ ./node_modules/express/lib/application.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/fs.realpath/old.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\fs.realpath'
 @ ./node_modules/fs.realpath/old.js 24:9-22
 @ ./node_modules/fs.realpath/index.js
 @ ./node_modules/glob/glob.js
 @ ./node_modules/cacache/lib/verify.js
 @ ./node_modules/cacache/verify.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/fs.realpath/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\fs.realpath'
 @ ./node_modules/fs.realpath/index.js 8:9-22
 @ ./node_modules/glob/glob.js
 @ ./node_modules/cacache/lib/verify.js
 @ ./node_modules/cacache/verify.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/glob/sync.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\glob'
 @ ./node_modules/glob/sync.js 4:9-22
 @ ./node_modules/glob/glob.js
 @ ./node_modules/cacache/lib/verify.js
 @ ./node_modules/cacache/verify.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/glob/glob.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\glob'
 @ ./node_modules/glob/glob.js 43:9-22
 @ ./node_modules/cacache/lib/verify.js
 @ ./node_modules/cacache/verify.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/graceful-fs/fs.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\graceful-fs'
 @ ./node_modules/graceful-fs/fs.js 3:9-22
 @ ./node_modules/graceful-fs/graceful-fs.js
 @ ./node_modules/enhanced-resolve/lib/NodeJsInputFileSystem.js
 @ ./node_modules/enhanced-resolve/lib/node.js
 @ (webpack)/lib/ResolverFactory.js
 @ (webpack)/lib/Compiler.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/graceful-fs/graceful-fs.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\graceful-fs'
 @ ./node_modules/graceful-fs/graceful-fs.js 1:9-22
 @ ./node_modules/enhanced-resolve/lib/NodeJsInputFileSystem.js
 @ ./node_modules/enhanced-resolve/lib/node.js
 @ (webpack)/lib/ResolverFactory.js
 @ (webpack)/lib/Compiler.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/loader-runner/lib/LoaderRunner.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\loader-runner\lib'
 @ ./node_modules/loader-runner/lib/LoaderRunner.js 5:9-22
 @ (webpack)/lib/NormalModule.js
 @ (webpack)/lib/AutomaticPrefetchPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/make-dir/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\make-dir'
 @ ./node_modules/make-dir/index.js 2:11-24
 @ ./node_modules/find-cache-dir/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/mime/mime.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\mime'
 @ ./node_modules/mime/mime.js 2:9-22
 @ ./node_modules/send/index.js
 @ ./node_modules/express/lib/response.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/mkdirp/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\mkdirp'
 @ ./node_modules/mkdirp/index.js 2:9-22
 @ (webpack)/lib/node/NodeOutputFileSystem.js
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/move-concurrently/move.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\move-concurrently'
 @ ./node_modules/move-concurrently/move.js 4:13-26
 @ ./node_modules/cacache/lib/util/move-file.js
 @ ./node_modules/cacache/lib/content/write.js
 @ ./node_modules/cacache/put.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/path-exists/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\path-exists'
 @ ./node_modules/path-exists/index.js 2:11-24
 @ ./node_modules/locate-path/index.js
 @ ./node_modules/find-up/index.js
 @ ./node_modules/pkg-dir/index.js
 @ ./node_modules/find-cache-dir/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/rimraf/rimraf.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\rimraf'
 @ ./node_modules/rimraf/rimraf.js 6:9-22
 @ ./node_modules/cacache/rm.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/schema-utils/dist/validateOptions.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\schema-utils\dist'
 @ ./node_modules/schema-utils/dist/validateOptions.js 11:10-23
 @ ./node_modules/schema-utils/dist/index.js
 @ ./node_modules/schema-utils/dist/cjs.js
 @ (webpack)/lib/BannerPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/send/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\send'
 @ ./node_modules/send/index.js 24:9-22
 @ ./node_modules/express/lib/response.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/snapdragon/lib/source-maps.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\snapdragon\lib'
 @ ./node_modules/snapdragon/lib/source-maps.js 3:9-22
 @ ./node_modules/snapdragon/lib/compiler.js
 @ ./node_modules/snapdragon/index.js
 @ ./node_modules/micromatch/lib/utils.js
 @ ./node_modules/micromatch/index.js
 @ (webpack)/lib/optimize/SideEffectsFlagPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/uglifyjs-webpack-plugin/node_modules/uglify-es/tools/node.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\uglifyjs-webpack-plugin\node_modules\uglify-es\tools'
 @ ./node_modules/uglifyjs-webpack-plugin/node_modules/uglify-es/tools/node.js 1:9-22
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/minify.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in (webpack)/lib/debug/ProfilingPlugin.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\webpack\lib\debug'
 @ (webpack)/lib/debug/ProfilingPlugin.js 1:11-24
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in (webpack)/lib/node/NodeMainTemplateAsync.runtime.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\webpack\lib\node'
 @ (webpack)/lib/node/NodeMainTemplateAsync.runtime.js 10:2-15 28:3-16
 @ (webpack)/lib/node/NodeMainTemplatePlugin.js
 @ (webpack)/lib/node/NodeTemplatePlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in (webpack)/lib/node/NodeOutputFileSystem.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\webpack\lib\node'
 @ (webpack)/lib/node/NodeOutputFileSystem.js 7:11-24
 @ (webpack)/lib/node/NodeEnvironmentPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/y18n/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\y18n'
 @ ./node_modules/y18n/index.js 1:9-22
 @ ./node_modules/cacache/lib/util/y.js
 @ ./node_modules/cacache/locales/en.js
 @ ./node_modules/cacache/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/index.js
 @ ./node_modules/uglifyjs-webpack-plugin/dist/cjs.js
 @ (webpack)/lib/WebpackOptionsDefaulter.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in (webpack)/lib/NormalModule.js
Module not found: Error: Can't resolve 'module' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\webpack\lib'
 @ (webpack)/lib/NormalModule.js 8:21-38
 @ (webpack)/lib/AutomaticPrefetchPlugin.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in (webpack)/lib/node/NodeTargetPlugin.js
Module not found: Error: Can't resolve 'module' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\webpack\lib\node'
 @ (webpack)/lib/node/NodeTargetPlugin.js 10:1-18
 @ (webpack)/lib/WebpackOptionsApply.js
 @ (webpack)/lib/webpack.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js

ERROR in ./node_modules/express/lib/request.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\pol2403\Documents\Node\test-app\node_modules\express\lib'
 @ ./node_modules/express/lib/request.js 18:11-25
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./app.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client ./app.js
ℹ 「wdm」: Failed to compile.

webpack.config.dev文件

var path = require('path');
webpack = require ('webpack');

module.exports  =  {
  devtool: 'inline-source-map',
  entry: [
    'webpack/hot/dev-server',
    'webpack-hot-middleware/client',
    path.resolve(__dirname, 'app.js')
  ],
  target: 'web',
  output: {
    path: '/',
    publicPath: 'http://localhost:3000/views/',
    filename: 'bundle.js'
  },
  plugins: [

  ],
  module: {
    rules: [
      {
          test: /\.js$/, 
          exclude: /node_modules/, 
          loaders: ['babel-loader']
    },
    {
        test: /\.ejs$/,
        loader: 'ejs-loader'} 
    ]
  }
};

app.js

var path = require ('path');
var express = require ('express');
var webpack = require ('webpack');
var webpackDevMiddleware = require ('webpack-dev-middleware');
var webpackHotMiddleware = require ('webpack-hot-middleware');

// routes
var index = require('./routes/index');
var users = require('./routes/users');

config = require ('./webpack.config.dev');

app = express();

// setup view engine
app.set('views', path.join(__dirname, 'views'));
app.set ('view engine', 'ejs');

app.use("/", index);
app.use("/users", users);

router = express.Router();

compiler = webpack(config);

app.use(webpackDevMiddleware(compiler, {
    publicPath: config.output.publicPath,
    stats: {colors: true}
}))

app.use(webpackHotMiddleware(compiler, {
    log: console.log
}))

app.listen(3000, () => console.log ('listening on 3000'));

module.exports = app;

视图/ index.js

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
 res.render('index', { title: 'Express' });
});

module.exports = router;​

路由/ index.ejs

<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <!-- <link rel='stylesheet' href='/stylesheets/style.css' /> -->
  </head>
  <body>
    <h1><%= title %></h1>
    <p>Welcome to <%= title %></p>
    <script src="bundle.js"></script>
  </body>
</html>​

1 个答案:

答案 0 :(得分:0)

尝试更仔细地阅读错误日志,它抱怨缺少的东西。如果你用谷歌搜索它们,你可能会找到答案。

我认为您最有可能使用 Webpack v5,它删除了通常会包含的一堆 polyfill,例如 fsprocessRead more about it here 尤其是 how they removed NodeJS polyfills 在他们的发行说明中

<块引用>

webpack 5 停止自动填充这些核心模块并专注于前端兼容模块。我们的目标是提高与 Web 平台的兼容性,其中 Node.js 核心模块不可用。

这只是我的预感,从您提供的堆栈跟踪中的此错误消息中读取:

Module not found: Error: Can't resolve 'fs'

您的 webpack 配置针对 web(通过 target)属性,因此用于操作文件系统的 fs 模块显然在浏览器中不可用。但是我看到您的应用程序正在使用在 NodeJS 环境中运行的 express。所以我认为您应该将 target 切换到 node 并阅读有关 Webpack NodeJS 配置的信息。有 articles 可以帮助您。