npm run dev 无法安装webpack cli

时间:2021-05-05 05:50:51

标签: laravel npm webpack npm-install laravel-mix

我有一个 laravel 应用程序:

  • laravel 7.30.4 版
  • npm 版本 6.14.6
  • 节点版本 12.18.3

当我想跑 npm run dev 时,我有这个问题

    CLI for webpack must be installed.
    webpack-cli (https://github.com/webpack/webpack-cli)
    Do you want to install 'webpack-cli' (yes/no):

输入 yes 后,我遇到了这个错误

    Error: Cannot find module 'webpack-cli/package.json'
    Require stack:
    - C:\Users\SibCo\AppData\Roaming\npm-cache\_npx\5852\node_modules\webpack\bin\webpack.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.resolve (internal/modules/cjs/helpers.js:78:19)
    at runCli (C:\Users\SibCo\AppData\Roaming\npm-cache\_npx\5852\node_modules\webpack\bin\webpack.js:50:26)
    at C:\Users\SibCo\AppData\Roaming\npm-cache\_npx\5852\node_modules\webpack\bin\webpack.js:139:5
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    'C:\\Users\\SibCo\\AppData\\Roaming\\npm-cache\\_npx\\5852\\node_modules\\webpack\\bin\\webpack.js'
     ]
    }

3 个答案:

答案 0 :(得分:0)

尝试全局安装 webpack:

npm install -g webpack webpack-cli

答案 1 :(得分:0)

如果您使用 webpack-cli 4webpack 5,请将 webpack-dev-server 更改为 webpack serve

示例:

"serve": "webpack serve --config config/webpack.dev.js --progress"

您可能还想在 GitHub 上查看此评论:

NPM package.json 脚本是一种方便且有用的方法,可以运行本地安装的二进制文件,而无需担心它们的完整路径。简单地定义一个脚本:

对于 webpack-cli 3.x:

"scripts": { "start:dev": "webpack-dev-server" }

对于 webpack-cli 4.x:

"scripts": { "start:dev": "webpack serve" }

答案 2 :(得分:0)

更新我的npm版本到v7.11.2并删除node_modules和dun :

    npm install

再次,它对我有用。