webpack --devtool不起作用,我该如何修复它?

ruarlubt  于 2022-11-24  发布在  Webpack
关注(0)|答案(1)|浏览(224)

我在Youtube上跟随ReactJS教程,我在运行“npm start”时卡住了,因为终端上有一个错误:
[webpack-cli]错误:缺少选项'-d,--devtool '参数[webpack-cli]运行'webpack --help'以查看可用命令和选项
webpack.config.js

import webpack from 'webpack';
import { resolve } from 'path';

var DIST_DIR = resolve(__dirname, "dist");
var SRC_DIR = resolve(__dirname, "src");

var config = {
    mode: 'development',
    devtool: 'source-map',
    debug: true,
    entry: SRC_DIR + "/app/index.js",
    output: {
        path: DIST_DIR + "/app",
        filename: "bundle.js",
        publicPath: "/app/"
    },
    modules: {
        loaders: [
            {
                test: /\.js?/,
                include: SRC_DIR,
                loader: "babel-loader",
                query: {
                    presets: ["react", "es2015", "stage-2"]
                }
            }
        ]
    }
};

export default config;

package.json

{
  "name": "reactjs-tutorials-academind-youtube",
  "version": "1.0.0",
  "description": "I learn ReactJS on Academind Tutorials on Youtube :)",
  "main": "index.js",
  "scripts": {
    "start": "npm run build",
    "build": "webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
    "build:prod": "webpack -p && cp src/index.html dist/index.html"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/khye1/ReactJS-Academind-Tutorial.git"
  },
  "author": "MeoCon22",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/khye1/ReactJS-Academind-Tutorial/issues"
  },
  "homepage": "https://github.com/khye1/ReactJS-Academind-Tutorial#readme",
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "webpack": "^5.75.0"
  },
  "devDependencies": {
    "babel-loader": "^9.1.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "webpack-cli": "^5.0.0",
    "webpack-dev-server": "^4.11.1"
  }
}

链接教程:https://www.youtube.com/watch?v=uextYhQGP6k&list=PL55RiY5tL51oyA8euSROLjMFZbXaV7skS&index=2
非常感谢。〈3
我试着运行“npm start”,但是出现了一个错误。我该如何修复这个错误?

wnavrhmk

wnavrhmk1#

尝试将脚本更改为. "scripts": { "start": "webpack serve --open", "build": "webpack" }

相关问题