ERROR in multi (webpack)-dev-server/client?http://localhost:8080 ./src Module not found: Error: C...

景星华
2023-12-01

出错现象

这个错误是我在用vue-cli中使用webpack打包的时候,进行环境分离操作,将webpack.config.js分成三个包

  • webpack.common.js
  • webpack.dev.js
  • webpack.prod.js

之后启动npm run serve(也就是webpack-dev-server --open)的时候报的错误,package.json文件是下面这样

"scripts": {
    "serve": "webpack-dev-server --open",
    "build": "webpack --config webpack.prod.js"
  },

报错信息

ERROR in Entry module not found: Error: Can’t resolve ‘./src’ in ‘E:\professer\lagou\lagou-homework\fed-e-task-02-02\code\vue-app-base’

ERROR in multi (webpack)-dev-server/client?http://localhost:8080 ./src
Module not found: Error: Can’t resolve ‘./src’ in ‘E:\professer\lagou\lagou-homework\fed-e-task-02-02\code\vue-app-base’
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src main[1]

出错原因

默认的配置入口是webpack.config.js,修改之后webpack-dev-server命令找不到打包入口。

解决方案

指定运行配置文件为webpack.dev.js

"scripts": {
    "serve": "webpack-dev-server --config webpack.dev.js --open",
    "build": "webpack --config webpack.prod.js"
  },

it works~

 类似资料: