Webpack-cli init not working

So I’m on the very last lecture of The Ultimate Javascript Series Part - 2, and the lecture is titled “Webpack”. I installed npm i -g [email protected] as intstructed, so far so good. Then I tried webpack-cli init and it’s giving me an error: TypeError: env.run(…).on is not a function.

Is anyone else having this problem???

Thanks,

1 Like

I found this in a search, it seems like a good solution. Did you ever figure it out?

No I got frustrated and moved on to the React Course. While looking at the link you just sent I tried using

  • webpack-cli 3.3.11
  • then npm install -D @webpack-cli/[email protected]
    and neither one of them worked for me. I could try the same versions of npm and node but I’m afraid that’ll screw up all my Node.JS files.

Have you thought about recreating the problem on a virtual machine? That way you have no worries about messing something up. Good luck. I’m slammed with homework, otherwise, I’d help you troubleshoot. Good luck!

Try this it fixed my issue.
npm i -g [email protected]

3 Likes

Im facing the same issue

Have you been able to fix your issue. I’m having same.

Did anyone ever find a fix for this. I’m just finishing up the JS course
and I get snagged on the last freakin’ lesson. I’m getting a slew of errors
following the directions in the video. I’ve tried several different things
(I’m not sure if I’ve messed something up under the hood), but I got nothing.

I guess I’ll just be watching the last lecture and keep moving until I learn more
about webpack down the road.

If anyone finds a solution, please let me know.

Hang on a sec. I think I got it working. But please don’t quote me, I don’t know if it’s correct or not.

I didn’t end up using what Mosh showed in the original video.
First I entered:
npm install --save-dev webpack-cli

Then I entered:
npm audit fix
(To deal with vulnerabilities)

Next:
webpack-cli init

And when prompted with → Would you like to install ‘@webpack-cli/generators’ package? (That will run ‘npm install -D @webpack-cli/generators’) (Y/n)
I chose Y

I’m then prompted with the webpack questions, some were the same as in the video, but some weren’t. I guessed my way through some of the ones I wasn’t sure about (probably not best practice, but we’ll cross that bridge when we come to it :laughing: )

I hope that helps someone who’s stuck.

Looking for premium quality jackets with a wide range of varieties. Well, Right Jackets is the place you wanna be. We deal with jackets of all types. We intend to provide our customers with the most premium quality jackets like thatryan reynolds spirited jacket. So we make our jackets from pure materials.

Can you please help me provide solution on what you responded in the prompt while trying to configure / respond to the prompt questions about the webpack. It still didn’t run or compile my bundle when i cant to run: “npm run bundle”. i got error messages and didnt work. i
Were you able to have any solution?

Here’s the fix that worked for me (and not mentioned in previous replies).

------ THE PROBLEM ------
There seemed to be an incompatible “version pairing” between Node and webpack-cli.

------ MY RESEARCH ------
As of 3/27/25, here are the version pairings that did and didn’t work for me.

Version pairing that DID NOT work:

Node: 10.9.0
webpack-cli: 6.0.1 (installed using: npm i -g webpack-cli)

The above version pairing produces the following error when running webpack-cli init.

webpack-cli init
[webpack-cli] Unknown command or entry ‘init’
[webpack-cli] Did you mean ‘info’ (alias ‘i’)?
[webpack-cli] Run ‘webpack --help’ to see available commands and options

Version pairing that works:

Node: 10.9.0
webpack-cli: 5.1.4 (installed using: npm i -g [email protected])
(List of webpack-cli versions: webpack-cli - npm)

MY RESULTS (using webpack-cli ver 5.1.4):

After running webpack-cli init for the first time, I am prompted with the following, to which I chose ‘Y’:

webpack-cli init

[webpack-cli] For using this command you need to install: ‘@webpack-cli/generators’ package.
[webpack-cli] Would you like to install ‘@webpack-cli/generators’ package? (That will run ‘npm install -D @webpack-cli/generators’) (Y/n) Y

This process added the following items to the root folder of my project:

  • node_modules folder
  • package-lock.json
  • package,json

I ran webpack-cli init again, this time getting the expected config questions.
(The questions I got were a bit different than what we see in Mosh’s video…he used webpack-cli ver 2.0.14.)

The questions I got:

webpack-cli init

? Which of the following JS solutions do you want to use? ES6
? Do you want to use webpack-dev-server? No
? Do you want to simplify the creation of HTML files for your bundle? No
? Do you want to add PWA support? No
? Which of the following CSS solutions do you want to use? none
? Do you like to install prettier to format generated configuration? No
? Pick a package manager: npm
? Overwrite package.json? Y
? Overwrite src\index.js? N
? Overwrite index.html? N

[webpack-cli] Project has been initialised with webpack!

Next, Mosh’s video has us create and edit a package.json file, but this step was not necessary since running webpack-cli init the second time automatically created the package.json file, and put the necessary “build:” “webpack…” script in place.
(Side note: the only thing I added was the watch switch (-w) in the “build” script.)

Next, Mosh has us bundle the app by running npm run build. However, on first run I got the following error:

Error: Cannot find package ‘@babel/plugin-syntax-dynamic-import’ imported from…

Fortunately, I discovered I could bypass this error and finish building the bundle if, before running npm run build, I renamed the .babelrc file so as to “hide” it (located in the root folder of my project). Perhaps with the Babel version that webpack-cli downloaded, the .babelrc file is deprecated? I don’t know if hiding .babelrc is effective in all scenarios, but it worked in this case.

After renaming .babelrc, the build succeeded.

Finally, using Live Server (after repointing index.html to dist/main.js) the app successfully ran in the browser’s console.