You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JHipster React项目启动报错:Webpack-dev-server模块未找到

问题:JHipster React项目执行yarn start时Webpack Dev Server模块找不到错误

我刚创建了一个JHipster React项目,未修改任何Webpack配置,执行yarn start启动时出现以下Webpack开发服务器报错信息:

$ yarn start
yarn run v1.3.2
$ yarn run webpack:dev
$ yarn run webpack-dev-server -- --config webpack/webpack.dev.js --progress --inline --profile --port=9060
warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ node --max_old_space_size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server.js --config webpack/webpack.dev.js --progress --inline --profile --port=9060
module.js:557
    throw err;
    ^

Error: Cannot find module '/Users/andrewcarre/Desktop/familyhomestay/node_modules/webpack-dev-server/bin/webpack-dev-server.js'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:617:3
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Andrews-MBP:familyhomestay andrewcarre$

请问有什么解决思路吗?


解决思路

我来给你几个针对性的解决思路:

  • 重新安装完整依赖:报错核心是找不到webpack-dev-server模块,大概率是依赖安装不完整或者损坏。先删除现有依赖文件和锁文件,再重新安装:
    rm -rf node_modules yarn.lock
    yarn install
    
  • 清空Yarn缓存:有时候Yarn的缓存文件损坏会导致依赖安装异常,先清空缓存再重新安装:
    yarn cache clean
    rm -rf node_modules yarn.lock
    yarn install
    
  • 检查Node.js版本兼容性:JHipster对Node.js版本有明确要求,你可以查看项目根目录的.nvmrc文件,确认当前使用的Node.js版本是否符合要求。版本不兼容可能导致依赖安装失败,建议切换到指定版本后再重新安装依赖。
  • 验证package.json中的依赖配置:查看项目package.json里的webpack-dev-server版本号,确保这个版本是存在且可正常安装的。如果版本号有问题(比如标记为过时或不存在的版本),可以尝试修改为兼容的稳定版本后再执行安装。

内容的提问来源于stack exchange,提问作者SomethingsGottaGive

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:00:26