webpack command not working

前端 未结 7 1813
谎友^
谎友^ 2020-12-01 04:09

I am new to Node Js and Webpack. I tried to start a project with module-loaders.

Firstly, I installed nodeJs and NPM and created a new directory called tutoria

相关标签:
7条回答
  • 2020-12-01 04:36

    Installing webpack with -g option installs webpack in a folder in

    C:\Users\<.profileusername.>\AppData\Roaming\npm\node_modules

    same with webpack-cli and webpack-dev-server

    Outside the global node_modules a link is created for webpack to be run from commandline

    C:\Users\<.profileusername.>\AppData\Roaming\npm

    to make this work locally, I did the following

    1. renamed the webpack folder in global node_modules to _old
    2. installed webpack locally within project
    3. edited the command link webpack.cmd and pointed the webpack.js to look into my local node_modules folder within my application

    Problem with this approach is you'd have to maintain links for each project you have. Theres no other way since you are using the command line editor to run webpack command when installing with a -g option.

    So if you had proj1, proj2 and proj3 all with their local node_modules and local webpack installed( not using -g when installing), then you'd have to create non-generic link names instead of just webpack.

    example here would be to create webpack_proj1.cmd, webpack_proj2.cmd and webpack_proj3.cmd and in each cmd follow point 2 and 3 above

    PS: dont forget to update your package.json with these changes or else you'll get errors as it won't find webpack command

    0 讨论(0)
  • 2020-12-01 04:39
    npm i webpack -g
    

    installs webpack globally on your system, that makes it available in terminal window.

    0 讨论(0)
  • 2020-12-01 04:43

    Actually, I have got this error a while ago. There are two ways to make this to work, as per my knowledge.

    1. Server wont update the changes made in the index.js because of some webpack bugs. So, restart your server.
    2. Updating your node.js will be helpful to avoid such problems.
    0 讨论(0)
  • 2020-12-01 04:45

    The quickest way, just to get this working is to use the web pack from another location, this will stop you having to install it globally or if npm run webpack fails.

    When you install webpack with npm it goes inside the "node_modules\.bin" folder of your project.

    in command prompt (as administrator)

    1. go to the location of the project where your webpack.config.js is located.
    2. in command prompt write the following
    "C:\Users\..\ProjectName\node_modules\.bin\webpack" --config webpack.config.vendor.js
    
    0 讨论(0)
  • 2020-12-01 04:47

    You can run npx webpack. The npx command, which ships with Node 8.2/npm 5.2.0 or higher, runs the webpack binary (./node_modules/.bin/webpack) of the webpack package. Source of info: https://webpack.js.org/guides/getting-started/

    0 讨论(0)
  • 2020-12-01 05:01

    I had to reinstall webpack to get it working with my local version of webpack, e.g:

    $ npm uninstall webpack
    $ npm i -D webpack
    
    0 讨论(0)
提交回复
热议问题