Zsh: command not found: webpack

后端 未结 6 968
借酒劲吻你
借酒劲吻你 2021-02-04 01:54

I\'m learning React and installed webpack through npm to my project directory but zsh is not finding the command even though I can see webpack installed in my project. I used

相关标签:
6条回答
  • 2021-02-04 02:28

    EDIT: Don't do this. Bad practice.

    Easy way. Install it globally.

    npm i -g webpack
    

    If you will work with webpack, install webpack-dev-server too

    npm i -g webpack-dev-server
    

    I recommend you first learn a bit about npm and then webpack.

    0 讨论(0)
  • 2021-02-04 02:33

    if you're on windows, try to get %USERPROFILE%\Appdata\Roaming\npm into your path and try again.

    0 讨论(0)
  • 2021-02-04 02:37

    having webpack installed locally, you could also use:

    $(npm bin)/webpack
    

    instead of:

    ./node_modules/.bin/webpack
    
    0 讨论(0)
  • 2021-02-04 02:39

    Installing node modules globally is a quick solution, but i recommend to add ./node_modules/.bin to the path variable and try to understand, what's the problem.

    Execute

    ~ export PATH="./node_modules/.bin:$PATH"
    

    Afterwards you can simply use all packages installed locally in your project. Also commands like mocha or eslint can be executed without installing these packages globally. There are several good explanations out there maybe also read this answer.

    0 讨论(0)
  • 2021-02-04 02:39

    In my case I had this problem with webpack, grunt and gulp and seems that my problem was an issue with permissions.

    I installed webpack and grunt globally. However, even then, $ webapack or $ grunt resulted in command not found

    The problem was that npm installed the global packages to /usr/local/lib/node_modules which required root permissions.

    So, to avoid having to use root permissions, I changed the directory in which global packages are to be installed to a directory in $HOME. To do this, I followed this guide:

    Install npm packages globally without sudo on macOS and Linux

    After this, I installed webpack and grunt globally again (this time without sudo) and verified that they have been installed in my new directory.

    Now, I can run without problem!

    $ webpack

    and

    $ grunt

    0 讨论(0)
  • 2021-02-04 02:52

    There is no need to install webpack globally.

    Try my way:

    First, in your package.json file, add this:

    "scripts": {
       "start": "webpack"
    },
    

    Then, in your terminal, run

    $npm start
    

    Another quick way: Just run (Yes, it is 'npx')

    $npx webpack
    

    That's all.

    0 讨论(0)
提交回复
热议问题