webpack打包提示: Uncaught Error: Cannot find module 'strip-ansi'
运行webpack-dev-server的时候,可以正常启动服务,但是Terminal控制台报错,如下:
ERROR in ./node_modules/webpack-dev-server/client/index.js?http://0.0.0.0:8085 6:16-37 Module not found: Error: Can't resolve 'strip-ansi' in 'D:\study\webpack+TS\node_modules\webpack-dev-server\client' ERROR in ./node_modules/webpack-dev-server/client/index.js?http://0.0.0.0:8085 8:13-32 Module not found: Error: Can't resolve './socket' in 'D:\study\webpack+TS\node_modules\webpack-dev-server\client' ERROR in ./node_modules/webpack-dev-server/client/index.js?http://0.0.0.0:8085 10:14-34 Module not found: Error: Can't resolve './overlay' in 'D:\study\webpack+TS\node_modules\webpack-dev-server\client' ERROR in ./node_modules/webpack-dev-server/client/index.js?http://0.0.0.0:8085 12:15-37 Module not found: Error: Can't resolve './utils/log' in 'D:\study\webpack+TS\node_modules\webpack-dev-server\client' ERROR in ./node_modules/webpack-dev-server/client/index.js?http://0.0.0.0:8085 16:18-48 Module not found: Error: Can't resolve './utils/sendMessage' in 'D:\study\webpack+TS\node_modules\webpack-dev-server\client' ERROR in ./node_modules/webpack-dev-server/client/index.js?http://0.0.0.0:8085 18:16-44 Module not found: Error: Can't resolve './utils/reloadApp' in 'D:\study\webpack+TS\node_modules\webpack-dev-server\client' ERROR in ./node_modules/webpack-dev-server/client/index.js?http://0.0.0.0:8085 20:22-56 Module not found: Error: Can't resolve './utils/createSocketUrl' in 'D:\study\webpack+TS\node_modules\webpack-dev-server\client' ERROR in ./node_modules/webpack/hot/dev-server.js 11:11-27 Module not found: Error: Can't resolve './log' in 'D:\study\webpack+TS\node_modules\webpack\hot' ERROR in ./node_modules/webpack/hot/dev-server.js 30:4-33 Module not found: Error: Can't resolve './log-apply-result' in 'D:\study\webpack+TS\node_modules\webpack\hot' ERROR in ./node_modules/webpack/hot/dev-server.js 50:18-38 Module not found: Error: Can't resolve './emitter' in 'D:\study\webpack+TS\node_modules\webpack\hot'
尝试过的方法【无效】
1.重新安装 strip-ansi
yarn add strip-ansi -D
2.删除node_modules目录,重新安装依赖
rm -rf node_modules
yarn install
3.重新安装本地webpack
yarn add webpack -D
以上3种方法均未解决问题
解决问题
仔细排查了一下发现,extensions配置扩展名称的问题(我只写了.ts的问题)
写的不对 没有加. 或者写的不全面
extensions: ['.js', '.ts', '.json', '.less', '.css']