簡體   English   中英

命令“npm run dev”不起作用,我該怎么辦?

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

我正在嘗試 npm 在 cmd 中運行 dev 並且它拋出了一個錯誤我已經嘗試了很多東西,但它似乎不起作用。

這是我的 package.json 文件:

           {
  "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"
  }
}

這是我的 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'
};

我更新了我的 npm,嘗試了 npm cache clean --force 但是還有很多其他的東西,但似乎沒有任何效果。 請幫忙。

這是我得到的錯誤:

  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.

我以管理員身份使用 PowerShell 卸載了 webpack cli,並使用 PowerShell 安裝它,它對我來說非常有效。 這是一個管理問題,因此請確保使用 PowerShell 下載 cli。 這些是我使用的命令:

npm uninstall webpack webpack-cli

對於安裝:

npm install webpack webpack-cli --save-dev  

我希望我能有所幫助。 謝謝

你能試着改變你的 webpack.config.js 像這樣:

   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/",
  },
};

並修改 package.json 文件中的腳本 object ,如下所示:

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

},

最后運行這個命令: npm run serve

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM