Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 2 tasks
jamiek-acl opened this issue Jun 14, 2019 · 46 comments
Closed
1 of 2 tasks

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

jamiek-acl opened this issue Jun 14, 2019 · 46 comments

Comments

@jamiek-acl
Copy link

jamiek-acl commented Jun 14, 2019

  • 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

> acl-project-manager@0.0.1 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! acl-project-manager@0.0.1 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 acl-project-manager@0.0.1 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.

@hiroppy
Copy link
Member

hiroppy commented Jun 15, 2019

hmm. webpack-cli changed a directory structure...
related: https://github.com/webpack/webpack-cli/pull/781/files#diff-2ec72bdd4a30cf784ac1e831f1360746

But, why didn't you resolve this path? I want to know your webpkack-cli's version.
https://github.com/webpack/webpack-dev-server/blob/master/bin/webpack-dev-server.js#L53

@hiroppy
Copy link
Member

hiroppy commented Jun 15, 2019

I cannot reproduce this issue.

ᐅ npm i webpack-dev-server

+ webpack-dev-server@3.7.1
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.

+ webpack@4.34.0
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

> webpack-cli@3.3.4 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.

+ webpack-cli@3.3.4
added 21 packages from 21 contributors and audited 22506 packages in 5.154s
found 0 vulnerabilities

ᐅ npx webpack-dev-server
...  

@alexander-akait
Copy link
Member

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

@jamiek-acl
Copy link
Author

jamiek-acl commented Jun 17, 2019

@evilebottnawi and @hiroppy I'm on the latest

    "webpack-cli": "^3.3.4",

@hiroppy
Copy link
Member

hiroppy commented Jun 17, 2019

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

@jamiek-acl
Copy link
Author

It looks like you used webpack-dev-server@3.7.1, but I had the problem with version 3.2.1 (I am not able to upgrade).

@snaill
Copy link

snaill commented Jun 19, 2019

webpack-dev-server@3.7.1 is OK.

@snaill
Copy link

snaill commented Jun 19, 2019

webpack-dev-server@3.7.2 error: Cannot find module 'yargs'

@dhantke
Copy link

dhantke commented Jun 28, 2019

Same problem here.

  • webpack-dev-server@3.7.2: does not work
  • webpack-dev-server@3.7.1: works

@snaill thx for investigation!

@Dheeraj-GL
Copy link

same issue on 3.8.2

@sneeze-attack
Copy link

sneeze-attack commented Oct 19, 2019

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, {

@cjlarose
Copy link

cjlarose commented Jan 18, 2020

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

@jods4
Copy link

jods4 commented Feb 12, 2020

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

@alexander-akait
Copy link
Member

Please use webpack serve for run webpack-dev-server

@jods4
Copy link

jods4 commented Feb 12, 2020

@evilebottnawi thanks for the tip. Is there any doc? Is that equivalent to webpack-dev-server (hmr, etc.) moving forward with webpack 5?

@alexander-akait
Copy link
Member

No docs right now, webpack-cli is still in beta, docs will be improved before stable release

@jods4
Copy link

jods4 commented Feb 12, 2020

No problem, I'll figure it out. But it's the new way to run dev-server, with support for HMR?

@alexander-akait
Copy link
Member

@jods4 flags are unstable right now, please use the configuration file

@Loligplayer33
Copy link

I have the same issue with the webpack-cli 4.0.0 version. Is there some way to downgrade to an older version that works or how can i solve the problem?

@alexander-akait
Copy link
Member

Do not use webpack-cli@4, it is still in beta

@Loligplayer33
Copy link

Ok but how can I downgrade?

@alexander-akait
Copy link
Member

What is downgrade? We don't use webpack-cli@4, please look in own package.json

@Loligplayer33
Copy link

I got this, my question is how do i install an older (and working) version of webpack-cli?
This is probably quite obvious but I'm new to all this stuff ;)

@alexander-akait
Copy link
Member

npm i webpack-cli

@Loligplayer33
Copy link

Already tried this. It is adding + webpack-cli@4.0.0-beta.3 as the version...

@alexander-akait
Copy link
Member

alexander-akait commented Feb 12, 2020

Something wrong with a package manager because latest is 3.3.11 https://www.npmjs.com/package/webpack-cli

@Loligplayer33
Copy link

Thank you a lot! Unfortunately I have no idea what to look for or where the bug could be. Do you have any suggestions what to look out for? Or, if it is not to time consuming, here is a repo with the files. You would literually make my day. I try to set this thing up for hours now....
https://github.com/Loligplayer33/Portfolio-Website-2.0

@alexander-akait
Copy link
Member

alexander-akait commented Feb 12, 2020

Just change https://github.com/Loligplayer33/Portfolio-Website-2.0/blob/master/package.json#L29 to ^3.3.11, remove package-lock.json and run npm i again

@Loligplayer33
Copy link

can't thank you enough for your time ;)

@bigbizze
Copy link

I wrote a python script to fix the problem until it's patched.

You can just add the command to your package.json script after adding the file to your project (assuming you have python installed).

https://github.com/bigbizze/FixWebPackError-Cannot-find-module-webpack-cli-bin-config-yargs

@clio19
Copy link

clio19 commented Apr 25, 2020

Remove node_modules folder and if you are using yarn change to npm and run npm install otherwise remove yarn.lock

@Linbubin
Copy link

webpack-cli@4 this problem still exists
run npm install -D webpack-cli@3 to solve it

@unp
Copy link

unp commented Jul 8, 2020

I was trying to run yarn webpack-dev-server on an app running react-scripts. I forgot I had used create-react-app to bootstrap my app.

Running yarn start fixed the issue.

@xdvarpunen
Copy link

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.

@harsh1612-dec
Copy link

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! reactapp@1.0.0 start: webpack-dev-server --hot
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the reactapp@1.0.0 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

@matrunchyk
Copy link

matrunchyk commented Oct 4, 2020

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"

@matrunchyk
Copy link

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

@GurvirSingh
Copy link

GurvirSingh commented Oct 10, 2020

use the webpack-3.3.12 version npm i webpack-cli@3.3.12 and it should work!

@dmitriid

This comment has been minimized.

@alexander-akait
Copy link
Member

alexander-akait commented Oct 12, 2020

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

@dmitriid
Copy link

@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:

@alexander-akait
Copy link
Member

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

vvscode added a commit to nickovchinnikov/react-js-tutorial that referenced this issue Oct 13, 2020
@devenderbe
Copy link

@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.

@ekb72-B
Copy link

ekb72-B commented Oct 14, 2020

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! reactapp@1.0.0 start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the reactapp@1.0.0 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.

@renic
Copy link

renic commented Oct 14, 2020

running 3.3.12 resolved this for me.npm i webpack-cli@3.3.12

@BelisonRazer
Copy link

running 3.3.12 resolved this for me.npm i webpack-cli@3.3.12

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

@webpack webpack locked as off-topic and limited conversation to collaborators Oct 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests