簡體   English   中英

Webpack-dev-server錯誤:找不到模塊,無法理解為什么?

[英]Webpack-dev-server Error: Cannot find module , can't understand why?

我有一個新的項目和設置webpack用作模塊捆綁器但是當我使用npm啟動腳本啟動webpack-dev-server ,我收到一個錯誤

Error can't find module : 
  at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
    at Function.Module._load (internal/modules/cjs/loader.js:497:25)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)

雖然我寫的一切都是正確的,但我不明白為什么會發生這種情況? 誰能告訴我為什么會這樣?

這是我的package.json文件

{
  "name": "simple-webpack-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --config ./webapck.common.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^1.0.0",
    "html-webpack-plugin": "^3.2.0",
    "mini-css-extract-plugin": "^0.4.1",
    "style-loader": "^0.21.0",
    "webpack": "^4.15.1",
    "webpack-cli": "^3.0.8",
    "webpack-dev-server": "^3.1.4"
  }
}

這是我的webpack.common.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin') ;
module.exports = {
    entry:{
        index:'./src/index.js',
        app:'./src/app.js'
    },
    output: {
        path: path.join(__dirname,'dist'),
        filename: "[name].js"
    },
    module: {
        rules: [
            {
                test :/\.css$/,
                use:['style-loader','css-loader']
            }
        ]
    },
    plugins: [
      new HtmlWebpackPlugin(
          {
              chunks:['app'],
              template:'./index.html'
          }
      )
    ],
    devServer: {
        port:4000
    }
}

我在我的IDE中嘗試了你的項目設置,我想我找到了你的問題的解決方案,我認為你在package.json文件中寫了錯誤的配置名稱

您在磁盤中的文件名為webpack.common.js

package.json webapck.common.js中的文件名

所以要解決問題

將package.json中的文件名更改為webpack.common.js而不是webapck.common.js這將解決我認為的問題,將package.json 啟動腳本更改為

"start": "webpack-dev-server --config ./webpack.common.js"

暫無
暫無

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

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