繁体   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