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