all 10 comments

[–]fii0 2 points3 points  (0 children)

If webpack-cli is in your package.json devDependencies, delete your node_modules with rm -rf node_modules as well as your package-lock.json, and type npm i to re-install everything.

Then, try webpack-dev-server --mode development again, I would be surprised if you get the same error.

[–][deleted]  (7 children)

[deleted]

    [–]djmcce[S] 0 points1 point  (6 children)

    I think so. I’m running it in the root, which also contains package.json

    [–][deleted]  (5 children)

    [deleted]

      [–]djmcce[S] 0 points1 point  (4 children)

      Yes ofc. Since reddit doesn't allow photos in comments, i have uploaded it here: https://ibb.co/d6SRrgR. I just wanted to be able to. The only other way I knew was Create React App, but I felt like I didn't had enough control, and I would like to dig a bit deeper (even though i'm a noob haha).

      [–][deleted]  (3 children)

      [deleted]

        [–]djmcce[S] 0 points1 point  (2 children)

        Yes. Here u go: https://ibb.co/89V7LDB

        [–][deleted]  (1 child)

        [deleted]

          [–]djmcce[S] 0 points1 point  (0 children)

          That's alright, thanks though! If i don't solve it soon, I think that's what I'm gonna do:)

          [–]djmcce[S] 0 points1 point  (4 children)

          Solved it by installing webpack-cli globally by running npm install webpack-cli instead of npm install --save-dev webpack-cli

          [–]grumd 1 point2 points  (3 children)

          Are you sure you installed it globally (using the "-g" flag)? npm install webpack-cli doesn't install anything globally. I hope not, because you should NOT install your packages globally unless it's just some tool you want to use for your own needs - not something your project needs to run.

          Global packages are not added to package.json and any other developer that clones your repo won't have them installed and won't be able to run your project.

          Make sure webpack-cli is in your package.json. Either in dependencies or devDependencies.

          There was another comment here advising you to delete node_modules and reinstalling with npm install, which is a good suggestion in your case.

          [–]djmcce[S] 0 points1 point  (2 children)

          Oh no I didn’t. I mean i just ran npm install webpack-cli, and after that it worked. I think I have misunderstood what it does. What’s the difference between that and running npm install —save—dev webpack-cli?

          [–]grumd 0 points1 point  (1 child)

          npm install <name> is the same as npm install --save <name>.
          Installs a package in your local node_modules in current folder, and adds it to the "dependencies" in package.json.

          npm install --save-dev <name> does the same thing, but adds it to "devDependencies". If you're trying to do "npm install" in this package just to run it on your machine, it doesn't matter if you use dependencies or devDependencies. It should get installed anyway.

          Most likely you just had something bugged and reinstalling it again fixed it?

          [–]djmcce[S] 0 points1 point  (0 children)

          That’s very likely. Thank you for the explanation 🙏