简体   繁体   中英

The command 'npm run dev' is not working, what should I do?

I'm trying npm run dev in the cmd and it's throwing an error I've tried a lot of things but it doesn't seem to work.

Here is my package.json file:

           {
  "name": "project",
  "version": "1.0.0",
  "description": "project",
  "main": "index.js",
  "scripts": {
    "dev": "webpack"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.3.11",
    "webpack-dev-server": "^3.11.0"
  },
  "dependencies": {
    "babel-polyfill": "^6.26.0"
  }
}

Here is my wepack.config.js:

    const path = require('path');


module.export = {
    entry: './src/js/index.js',
    output: {
        path: path.resolve(__dirname, 'dist/js'),
        filename: 'bundle.js'
    },
    mode: 'development'
};

I updated my npm, tried npm cache clean --force but and many other things but nothing seems to work. Please help.

This is the error I get:

  Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.

Hash: c1735700111314ac598b
Version: webpack 4.43.0
Time: 62ms
Built at: 05/25/2020 1:24:29 PM

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in Entry module not found: Error: Can't resolve './src' in 'C:\Users\usman\Desktop\coding\Forkify'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! forkify@1.0.0 dev: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the forkify@1.0.0 dev 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\usman\AppData\Roaming\npm-cache\_logs\2020-05-25T08_24_29_792Z-debug.log.

I uninstalled webpack cli using PowerShell as administrator and installed it using PowerShell too, it worked perfectly for me. It is an administration problem so make sure to download cli using PowerShell. These were the commands that I used:

npm uninstall webpack webpack-cli

And for installation:

npm install webpack webpack-cli --save-dev  

I hope I am being helpful. Thanks

can you try to change your webpack.config.js like this:

   const path = require("path");

module.exports = {
  entry: "./src/js/index.js",
  output: {
    path: path.resolve(__dirname, "dist/js"),
    filename: "bundle.js",
  },
  devServer: {
    contentBase: path.resolve(__dirname, "dist"),
    publicPath: "/js/",
  },
};

and also modify the scripts object inside package.json file like below:

  "scripts": {
"serve": "webpack-dev-server --mode development"

},

and finally run this command: npm run serve

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM