Skip to content

Error: Cannot find module 'webpack-cli/bin/config-yargs' #2029

Closed

Description

@jamiek-acl
  • Operating System: Mac OS

  • Node Version: 10.15.1

  • NPM Version: 6.4.1

  • webpack Version: 4.34.0

  • webpack-dev-server Version: 3.2.1

  • This is a bug...?

  • This is a modification request

Code

// webpack.config.js
const path = require('path');
const config = require('./webpack.dev.config');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const newConfig = Object.assign({}, config);

newConfig.entry = ['@babel/polyfill', './app/features/Certifications/index', 'webpack/hot/only-dev-server'];

newConfig.output = {
  filename: 'webpack-certifications-bundle.js',
  path: path.resolve('../app/assets/webpack'),
  publicPath: '/',
};

newConfig.devServer = {
  historyApiFallback: true,
  hot: true,
  open: true,
  openPage: 'dashboard',
  port: 9000,
  proxy: {
    '/api': {
      target: 'http://localhost:9010',
      secure: false,
    },
  },
  publicPath: '/',
};

newConfig.plugins.push(new HtmlWebpackPlugin());

module.exports = newConfig;
module.exports.devtool = 'cheap-module-eval-source-map';
// package.json
scripts: {
  "dev:cert:webpack": "NODE_ENV=development webpack-dev-server --config webpack.dev.certifications.config.js"
}

Expected Behavior

Running npm run dev:cert:webpack starts webpack dev server.

Actual Behavior

~/src/projects/client$ npm run dev:cert:webpack

> [email protected] dev:cert:webpack /Users/jamie/src/projects/client
> NODE_ENV=development webpack-dev-server --config webpack.config.js

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

Error: Cannot find module 'webpack-cli/bin/config-yargs'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/jamie/src/projects/client/node_modules/webpack-dev-server/bin/webpack-dev-server.js:77:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev:cert:webpack: `NODE_ENV=development webpack-dev-server --config webpack.dev.certifications.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev:cert:webpack 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!     /Users/jamie/.npm/_logs/2019-06-14T23_23_20_044Z-debug.log

If I upgrade to webpack-dev-server 3.7.1, this error does not occur.

Thank you for your help.

Activity

  1. hiroppy commented on Jun 15, 2019

    @hiroppy
    Contributor
  2. hiroppy commented on Jun 15, 2019

    @hiroppy
    Contributor

    I cannot reproduce this issue.

    Details
    ᐅ npm i webpack-dev-server
    
    + [email protected]
    added 441 packages from 281 contributors and audited 3458 packages in 18.504s
    found 0 vulnerabilities
    
    ᐅ npx webpack-dev-server
    Cannot find module 'webpack'
    Require stack:
    - /Users/Desktop/test2/node_modules/webpack-dev-server/bin/webpack-dev-server.js
    
    ᐅ npm i webpack
    npm WARN saveError ENOENT: no such file or directory
    npm WARN enoent ENOENT: no such file or directory
    npm WARN test2 No description
    npm WARN test2 No repository field.
    npm WARN test2 No README data
    npm WARN test2 No license field.
    
    + [email protected]
    added 148 packages from 130 contributors and audited 15992 packages in 10.067s
    found 0 vulnerabilities
    
    ᐅ npx webpack-dev-server
    The CLI moved into a separate package: webpack-cli
    Please install 'webpack-cli' in addition to webpack itself to use the CLI
    -> When using npm: npm i -D webpack-cli
    -> When using yarn: yarn add -D webpack-cli
    Cannot find module 'webpack-cli/bin/config-yargs'
    Require stack:
    - /Users/Desktop/test2/node_modules/webpack-dev-server/bin/webpack-dev-server.js
    
    ᐅ npm i webpack-cli
    
    > [email protected] postinstall
    > node ./bin/opencollective.js
    
    
    
                                Thanks for using webpack!
                     Please consider donating to our Open Collective
                            to help us maintain this package.
    
    
    
                  👉  Donate: https://opencollective.com/webpack/donate
    
    
    npm WARN saveError ENOENT: no such file or directory
    npm WARN enoent ENOENT: no such file or directory
    npm WARN test2 No description
    npm WARN test2 No repository field.
    npm WARN test2 No README data
    npm WARN test2 No license field.
    
    + [email protected]
    added 21 packages from 21 contributors and audited 22506 packages in 5.154s
    found 0 vulnerabilities
    
    ᐅ npx webpack-dev-server
    ...  
  3. alexander-akait commented on Jun 15, 2019

    @alexander-akait
    Member

    You use old webpack-cli version, please update webpack-cli

  4. jamiek-acl commented on Jun 17, 2019

    @jamiek-acl
    Author

    @evilebottnawi and @hiroppy I'm on the latest

        "webpack-cli": "^3.3.4",
    
  5. hiroppy commented on Jun 17, 2019

    @hiroppy
    Contributor

    We cannot reproduce your issue. if we need to investigate this issue, please submit the reproducible repo.

  6. jamiek-acl commented on Jun 17, 2019

    @jamiek-acl
    Author

    It looks like you used [email protected], but I had the problem with version 3.2.1 (I am not able to upgrade).

  7. snaill commented on Jun 19, 2019

    @snaill
  8. snaill commented on Jun 19, 2019

    @snaill

    [email protected] error: Cannot find module 'yargs'

  9. dhantke commented on Jun 28, 2019

    @dhantke

    Same problem here.

    @snaill thx for investigation!

  10. Dheeraj-GL commented on Oct 17, 2019

    @Dheeraj-GL

    same issue on 3.8.2

  11. sneeze-attack commented on Oct 19, 2019

    @sneeze-attack

    I ran into this issue after updating webpack-cli from:

    webpack-cli ^3.2.1 → ^3.3.9

    I fixed it by changing:

    node_modules\webpack-dev-server\bin\webpack-dev-server.js

    Line 84:
    require('webpack-cli/bin/config-yargs')(yargs);
    To:
    require('webpack-cli/bin/config/config-yargs')(yargs);

    Line 92:
    const config = require('webpack-cli/bin/convert-argv')(yargs, argv, {
    To:
    const config = require('webpack-cli/bin/utils/convert-argv')(yargs, argv, {

  12. cjlarose commented on Jan 18, 2020

    @cjlarose

    Fixed in #1754. Upgrade to webpack-dev-server 3.3.0 or higher.

  13. jods4 commented on Feb 12, 2020

    @jods4

    This is broken again when using webpack-cli 4.0.0 (in beta). There's only cli.js left inside webpack-cli/bin.

  14. alexander-akait commented on Feb 12, 2020

    @alexander-akait
    Member

    Please use webpack serve for run webpack-dev-server

  15. 21 remaining items

  16. xdvarpunen commented on Sep 16, 2020

    @xdvarpunen

    I had windows update today that prevented recognizing webpack and webpack-cli. After finishing the update and restarting PC the project recognized webpack and webpack-cli again.

  17. harsh1612-dec commented on Sep 19, 2020

    @harsh1612-dec

    I had windows update today that prevented recognizing webpack and webpack-cli. After finishing the update and restarting PC the project recognized webpack and webpack-cli again.

    webpack-dev-server --hot

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

    Error: Cannot find module 'webpack/bin/config-yargs'
    Require stack:

    • C:\Users\Harsh Agarwal\Desktop\reactapp\node_modules\webpack-dev-server\bin\webpack-dev-server.js
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
      at Function.Module._load (internal/modules/cjs/loader.js:841:27)
      at Module.require (internal/modules/cjs/loader.js:1025:19)
      at require (internal/modules/cjs/helpers.js:72:18)
      at Object. (C:\Users\Harsh Agarwal\Desktop\reactapp\node_modules\webpack-dev-server\bin\webpack-dev-server.js:54:1)
      at Module._compile (internal/modules/cjs/loader.js:1137:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
      at Module.load (internal/modules/cjs/loader.js:985:32)
      at Function.Module._load (internal/modules/cjs/loader.js:878:14)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
      code: 'MODULE_NOT_FOUND',
      requireStack: [
      'C:\Users\Harsh Agarwal\Desktop\reactapp\node_modules\webpack-dev-server\bin\webpack-dev-server.js'
      ]
      }
      npm ERR! code ELIFECYCLE
      npm ERR! errno 1
      npm ERR! [email protected] start: webpack-dev-server --hot
      npm ERR! Exit status 1
      npm ERR!
      npm ERR! Failed at the [email protected] start 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\Harsh Agarwal\AppData\Roaming\npm-cache_logs\2020-09-19T03_56_55_540Z-debug.log

    Kindly help me with this i cant find solution from past 3 days

  18. matrunchyk commented on Oct 4, 2020

    @matrunchyk

    Same to me:

    "webpack": "^5.0.0-rc.3",
    "webpack-cli": "^4.0.0-rc.0",
    "webpack-dev-server": "^3.11.0"
    

    Works:

    "webpack": "^5.0.0-rc.3",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0"
    
  19. matrunchyk commented on Oct 4, 2020

    @matrunchyk

    @evilebottnawi wanna reopen or should I create a new issue?

  20. GurvirSingh commented on Oct 10, 2020

    @GurvirSingh

    use the webpack-3.3.12 version npm i [email protected] and it should work!

  21. dmitriid commented on Oct 12, 2020

    @dmitriid
  22. alexander-akait commented on Oct 12, 2020

    @alexander-akait
    Member

    Need update webpack-cli to v4 (stable) and change webpack-dev-server bin in package.json on webpack serve:

    Old:

    package.json

    {
      "scripts": {
        "serve": "webpack-dev-server"
      },
      "devDependencies": {
        "webpack-cli": "^3.3.12"
      }
    }

    New:

    package.json

    {
      "scripts": {
        "serve": "webpack serve"
      },
      "devDependencies": {
        "webpack-cli": "^4.0.0"
      }
    }

    Please read my answer careful

  23. dmitriid commented on Oct 12, 2020

    @dmitriid

    @evilebottnawi Your answer is somewhere in the middle of 20-30 replies to this issues. It's nowhere in the README. The version didn't change, but somehow the behaviour broke due to a release of an external lib?

    Dependabot has bumped cli version for quite a number of projects, so expect a lot of people flocking to this issue and potentially missing a response.

    The best way to solve this is just to add a line to the README:

    NPM package.json scripts are a convenient and useful means to run locally installed binaries without having to be concerned about their full paths. Simply define a script as such:
    
    + For webpack-cli 3.x:
    +
    "scripts": {
      "start:dev": "webpack-dev-server"
    }
    
    + For webpack-cli 4.x:
    +
    + "scripts": {
    +  "start:dev": "webpack serve"
    +}
    
    And run the following in your terminal/console:
  24. alexander-akait commented on Oct 12, 2020

    @alexander-akait
    Member

    Yes, we are working on bugs in webpack-cli, it will be improved after this

  25. added a commit that references this issue on Oct 13, 2020
  26. devenderbe commented on Oct 14, 2020

    @devenderbe

    @evilebottnawi Your answer is somewhere in the middle of 20-30 replies to this issues. It's nowhere in the README. The version didn't change, but somehow the behaviour broke due to a release of an external lib?

    Dependabot has bumped cli version for quite a number of projects, so expect a lot of people flocking to this issue and potentially missing a response.

    The best way to solve this is just to add a line to the README:

    NPM package.json scripts are a convenient and useful means to run locally installed binaries without having to be concerned about their full paths. Simply define a script as such:
    
    + For webpack-cli 3.x:
    +
    "scripts": {
      "start:dev": "webpack-dev-server"
    }
    
    + For webpack-cli 4.x:
    +
    + "scripts": {
    +  "start:dev": "webpack serve"
    +}
    
    And run the following in your terminal/console:

    "start": "webpack serve --mode development --open" it's working fine but without using --open. But giving error on adding --open.

  27. ekb72-B commented on Oct 14, 2020

    @ekb72-B

    Hi All, having trouble with this as well.

    > webpack-dev-server --mode development --open --hot
    
    internal/modules/cjs/loader.js:883
      throw err;
      ^
    
    Error: Cannot find module 'webpack-cli/bin/config-yargs'
    Require stack:
    - /usr/local/lib/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 require (internal/modules/cjs/helpers.js:88:18)
        at Object.<anonymous> (/usr/local/lib/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: [
        '/usr/local/lib/node_modules/webpack-dev-server/bin/webpack-dev-server.js'
      ]
    }
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] start: `webpack-dev-server --mode development --open --hot`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the [email protected] start 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:
    

    I changed the versions to recommended ones here, but the issue persists.

  28. renic commented on Oct 14, 2020

    @renic

    running 3.3.12 resolved this for me.npm i [email protected]

  29. BelisonRazer commented on Oct 18, 2020

    @BelisonRazer

    running 3.3.12 resolved this for me.npm i [email protected]

    downgraded 4.x => 3.3.12, it's work

  30. locked as off topic and limited conversation to collaborators on Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions