internal/modules/cjs/loader.js:968 throw err; ^ Error: Cannot find module ‘webpack-cli/bin/conf

webpack的devServer运行错误

PS D:\VScode_Project\vue\webpackstudy> npm install webpack-dev-server D
npm WARN deprecated D@1.0.0: Package no longer supported. Contact support@npmjs.com for more info.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN webpackstudy@1.0.0 No description

+ webpack-dev-server@3.11.2
+ D@1.0.0
added 373 packages from 231 contributors and audited 503 packages in 81.174s

29 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

PS D:\VScode_Project\vue\webpackstudy> npm run dev

> webpackstudy@1.0.0 dev D:\VScode_Project\vue\webpackstudy
> webpack

asset bundle.js 322 KiB [compared for emit] (name: main)
runtime modules 937 bytes 4 modules
cacheable modules 281 KiB
  ./src/index.js 149 bytes [built] [code generated]
  ./node_modules/jquery/dist/jquery.js 281 KiB [built] [code generated]
webpack 5.19.0 compiled successfully in 277 ms
PS D:\VScode_Project\vue\webpackstudy> npm run dev

> webpackstudy@1.0.0 dev D:\VScode_Project\vue\webpackstudy
> webpack-dev-server

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- D:\VScode_Project\vue\webpackstudy\node_modules\webpack-dev-server\bin\webpack-dev-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at Object.<anonymous> (D:\VScode_Project\vue\webpackstudy\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\VScode_Project\\vue\\webpackstudy\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webpackstudy@1.0.0 dev: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webpackstudy@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\hhy\AppData\Roaming\npm-cache\_logs\2021-01-31T03_02_12_501Z-debug.log

问题原因

webpack-dev-server和webpack-cli有版本对应问题,我使用的版本如下:
在这里插入图片描述

解决方案

1、运行命令卸载webpack-cli

PS D:\VScode_Project\vue\webpackstudy> npm uninstall webpack-cli
npm WARN webpackstudy@1.0.0 No description
npm WARN webpackstudy@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})  

removed 41 packages and audited 462 packages in 2.788s

24 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

如果报错,就从package.json中手动删除webpack-cli项(如下图),然后删除掉node_modules文件夹,运行cnpm install 重新安装依赖

2、安装低版本webpack-cli

在这里插入图片描述

PS D:\VScode_Project\vue\webpackstudy> npm install webpack-cli@3 -D
npm WARN webpack-cli@3.3.12 requires a peer of webpack@4.x.x but none is installed. You must install peer dependencies yourself.
npm WARN webpackstudy@1.0.0 No description
npm WARN webpackstudy@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})  

+ webpack-cli@3.3.12
added 42 packages from 27 contributors and audited 504 packages in 13.789s

24 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

3、安装成功后问题就解决了

PS D:\VScode_Project\vue\webpackstudy> npm run dev

> webpackstudy@1.0.0 dev D:\VScode_Project\vue\webpackstudy
> webpack-dev-server

i 「wds」: Project is running at http://localhost:8080/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from D:\VScode_Project\vue\webpackstudy
i 「wdm」: asset bundle.js 685 KiB [emitted] (name: main)
runtime modules 1.25 KiB 6 modules
cacheable modules 616 KiB
  modules by path ./node_modules/webpack-dev-server/client/ 20.9 KiB 10 modules
  modules by path ./node_modules/html-entities/lib/*.js 61 KiB 5 modules
  modules by path ./node_modules/url/ 37.4 KiB 3 modules
  modules by path ./node_modules/querystring/*.js 4.51 KiB
    ./node_modules/querystring/index.js 127 bytes [built] [code generated]
    ./node_modules/querystring/decode.js 2.34 KiB [built] [code generated]
    ./node_modules/querystring/encode.js 2.04 KiB [built] [code generated]
  modules by path ./node_modules/webpack/hot/*.js 1.42 KiB
    ./node_modules/webpack/hot/emitter.js 75 bytes [built] [code generated]
    ./node_modules/webpack/hot/log.js 1.34 KiB [built] [code generated]
./node_modules/webpack/hot/ sync nonrecursive ^\.\/log$ 170 bytes [built] [code generated]
webpack 5.19.0 compiled successfully in 476 ms
i 「wdm」: Compiled successfully.

如果对你有帮助,可以点赞收藏+关注哦

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当你看到这样的错误信息 "Error: Cannot find module 'node:path'",它通常表示Node.js在尝试加载名为 'node:path' 的模块时失败了。'node:path' 是 Node.js 自带的一个内置模块,它提供了路径操作相关的功能。 这个错误可能由以下几个原因引起: 1. 模块路径错误:确保你引用模块的路径正确无误。如果是异步加载,可能是模块的相对路径问题,或者模块名称拼写或大小写不一致。 2. 模块未安装:如果 'node:path' 是第三方模块,确保已经使用 `npm install node:path` 或者 `yarn add node:path` 安装了。 3. 模块更新问题:有时候更新了项目依赖,旧版本的模块不再可用,需要检查是否有更新到最新版本。 4. 文件系统问题:如果模块在预期的目录中,但Node.js无法访问,可能是权限问题或文件系统配置错误。 5. 初次运行:对于一些只在开发环境或特定条件下才使用的模块,初次运行时可能会因为环境变量设置不正确导致找不到。 为了解决这个问题,你可以按照以下步骤排查: 1. 检查代码中引入模块的方式是否正确。 2. 使用 `require.resolve('node:path')` 打印出实际查找的模块路径,确认是否能找到。 3. 如果是第三方模块,确保已经添加到项目的 `package.json` 的 `dependencies` 或 `devDependencies` 字段。 4. 重新启动开发服务器或清理并重新构建项目。 5. 在遇到问题时查阅模块文档或搜索错误信息,看是否有其他开发者遇到过类似问题。 如果你需要帮助调试,请提供具体的上下文和更多代码片段,以便更准确地定位问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值