命令“ npm run dev”失败

时间:2019-12-10 18:09:10

标签: javascript npm webpack

执行npm run dev时,出现以下错误。我还包括了package.json文件和配置文件。

  

C:\ Users \ aksha \ Desktop \ forkify> npm run dev

     

npm错误!缺少脚本:dev

     

npm错误!可以在以下位置找到此运行的完整日志:

     

npm错误!
  C:\ Users \ aksha \ AppData \ Roaming \ npm-cache_logs \ 2019-12-07T18_22_36_160Z-debug.log

webpack.config.js

const path = require('path');


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

};

package.json文件

{
  "name": "forkify",
  "version": "1.0.0",
  "description": "forkify project",
  "main": "index.js",
  "scripts": {
    "dev": "webpack"
  },
  "author": "Aditi Aella",
  "license": "ISC",
  "devDependencies": {
    "live-server": "^1.2.1",
    "webpack": "^4.41.2",
    "webpack-cli": "^2.1.5",
    "webpack-dev-server": "^3.9.0"
  }
}

1 个答案:

答案 0 :(得分:0)

尝试将path: path.resolve(__dirname, 'dist/js')文件中的path: path.join(__dirname, 'dist/js')更改为webpack.config.json,并在package.json文件中使用它:

"scripts": {
    "dev": "webpack-dev-server",
}