• Error: Cannot find module 'webpack-cli/bin/config-yargs' webpack编译时遇到的 npm run dev 报错问题


    1.错误信息

    E:ECMAScriptframe wo-sev> npm run dev

    > two-sev@1.0.0 dev E:ECMAScriptframe wo-sev
    > webpack-dev-server

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

    Error: Cannot find module 'webpack-cli/bin/config-yargs'             翻译: “无法找到webpack-cli/bin/config-yargs模块”
    Require stack:
    - E:ECMAScriptframe wo-sev ode_moduleswebpack-dev-serverinwebpack-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 require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (E:ECMAScriptframe wo-sev ode_moduleswebpack-dev-serverinwebpack-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: [
    'E:\ECMAScript\frame\two-sev\node_modules\webpack-dev-server\bin\webpack-dev-server.js'
    ]
    }

    1. npm ERR! code ELIFECYCLE

    npm ERR! errno 1
    npm ERR! two-sev@1.0.0 dev: `webpack-dev-server`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the two-sev@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:Users25369AppDataRoaming pm-cache\_logs2021-04-20T15_32_18_786Z-debug.log
    PS E:ECMAScriptframe wo-sev> npm uninstall webpack-cli
    npm WARN two-sev@1.0.0 No description
    npm WARN two-sev@1.0.0 No repository field.
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modulesfsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

    removed 42 packages in 12.568s

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

     2.解决方案

      版本不兼容

    webpack的版本与webpack-dev-server3.x 的版本不兼容

    1. 卸载当前的 webpack-cli npm uninstall webpack-cli

    2. 安装 webpack-cli 3.* 版本 npm install webpack-cli@3 -D    // 安装指定的版本

    或者卸载webpack-dev-server,安装webpack-dev-server指定的版本也行

    3.重新运行   npm    run    dev      运行结果如下

    npm run dev

    > two-sev@1.0.0 dev E:ECMAScriptframe wo-sev
    > webpack-dev-server

    i 「wds」: Project is running at http://localhost:8080/                       翻译:项目正在http://localhost:8080/运行
    i 「wds」: webpack output is served from /
    i 「wds」: Content not from webpack is served from E:ECMAScriptframe wo-sev
    i 「wdm」: asset bundle.js 687 KiB [emitted] (name: main)
    runtime modules 1.25 KiB 6 modules
    cacheable modules 618 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.34.0 compiled successfully in 1233 ms
    i 「wdm」: Compiled successfully.

    出现上面的代码,表示项目已运行成功,运行在http://localhost:8080/上,通过访问这个地址,查看项目

     浏览器中显示这个地址下的所有项目目录,通过点击目录,进入到相应目录文件

    编辑器打开src下的index.html文件

     发现根目录下并没有bundle.js文件,

     因为这个文件默认被隐藏掉了,是被放在内存中的文件

  • 相关阅读:
    Lodash 严重安全漏洞背后 你不得不知道的 JavaScript 知识
    SQL Server和C#中无法将小数字符串直接转换为整数类型
    Is default(CancellationToken) equivalent to CancellationToken.None?(转载)
    Stored Procedures: OUTPUT vs OUT?(转载)
    关于TransactionScope.Complete方法(链接)
    Do I need to dispose of Tasks?(链接)
    EF Core 3.0 Keyless Entity Types (链接)
    为什么C#接口中不能声明async异步函数(转载)
    How does SqlDataReader handle really large queries?(转载)
    ASP.NET Core MVC中的Filter如果不实现IFilterFactory接口,那么Filter默认情况下在ASP.NET Core生命周期内是单例的,会被重用
  • 原文地址:https://www.cnblogs.com/swhc/p/14683493.html
Copyright © 2020-2023  润新知