报错

Module not found: Error: Can't resolve 'D:\workSpace备份\vs\yygh\webpackdemo\src\src\main.js' in 'D:\workSpace备份\vs\yygh\webpackdemo\src'
resolve 'D:\workSpace备份\vs\yygh\webpackdemo\src\src\main.js' in 'D:\workSpace备份\vs\yygh\webpackdemo\src'
  No description file found in D:\workSpace备份\vs\yygh\webpackdemo\src or above
  No description file found in D:\workSpace备份\vs\yygh\webpackdemo\src\src or above
    D:\workSpace备份\vs\yygh\webpackdemo\src\src\main.js doesn't exist
  .js
    D:\workSpace备份\vs\yygh\webpackdemo\src\src\main.js.js doesn't exist
  .json
    D:\workSpace备份\vs\yygh\webpackdemo\src\src\main.js.json doesn't exist
  .wasm
    D:\workSpace备份\vs\yygh\webpackdemo\src\src\main.js.wasm doesn't exist
  as directory
    D:\workSpace备份\vs\yygh\webpackdemo\src\src\main.js doesn't exist

webpack 5.59.1 compiled with 1 error in 57 ms

解决

constpath=require("path") //Node.js内置模块
module.exports= {
    entry: './src/main.js', //配置入口文件
    output: {
        path: path.resolve(__dirname, './dist'), //输出路径,__dirname:当前文件所在路径
        filename: 'bundle.js'//输出文件
    }
}

改成

const path = require('path')
module.exports = {
  entry: path.join(__dirname, 'src/main.js'),
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist')
  }
}

Logo

前往低代码交流专区

更多推荐