简体   繁体   English

找不到Webpack 4 ./src目录

[英]Webpack 4 ./src directory not found

I am trying to split the webpack config to base, dev and prod configs. 我正在尝试将webpack配置拆分为基础配置,开发配置和产品配置。 Here is my entry section of webpack.base.babel.js file 这是我的webpack.base.babel.js文件的输入部分

module.exports = options => ({
   mode: options.mode,
   entry: options.entry,
   output: Object.assign(
     {
      // Compile into js/build.js
      path: path.resolve(process.cwd(), 'build'),
      publicPath: '/',
     },
     options.output,
   ), // Merge with env dependent settings

Here is the entry section of webpackdev.babel.js file: 这是webpackdev.babel.js文件的输入部分:

module.exports = require('./webpack.base.babel')({
  mode: 'development',

  // Add hot reloading in development
  entry: [
    require.resolve('react-app-polyfill/ie11'),
    'webpack-hot-middleware/client?reload=true',
    path.join(process.cwd(), 'app/app.js'), 
  ],

  // Don't use hashes in dev mode for better performance
  output: {
    filename: '[name].js',
    chunkFilename: '[name].chunk.js',
  },

My start script in package.json looks like: "start": "webpack-dev-server --mode development" 我在package.json中的启动脚本如下: "start": "webpack-dev-server --mode development"

But when I run npm start I get the bellow error: 但是当我运行npm start时,出现以下错误:

ERROR in Entry module not found: Error: Can't resolve './src' 在输入模块中找不到错误:错误:无法解析“ ./src”

. I am on Windows 10. Could anybody explain what's wrong with my webpack config. 我在Windows 10上。有人可以解释我的Webpack配置有什么问题吗? I am specifying the entry file as app/app.js but still webpack is defaulting to src/index.js . 我将入口文件指定为app/app.js但webpack仍默认为src/index.js

Thanks in advance. 提前致谢。

Just hand in your webpack config explicitely by changing your npm start script to: 只需将npm start脚本更改为明确地上交Webpack配置:

"start": "webpack-dev-server --config webpackdev.babel.js"

Webpack searches for webpack.config.js in the root folder automatically. Webpack webpack.config.js在根文件夹中自动搜索webpack.config.js Starting with v4, Webpack also claims to be a zero config bundler, so it will use opinionated defaults , if no config can be located. 从v4开始,Webpack还声称自己是零配置捆绑器,因此,如果找不到任何配置,它将使用默认的默认值 Eg: 例如:

  • entry point of your project is assumed to be src/index 项目的入口点假定为src/index
  • output will be put in dist/main.js 输出将放在dist/main.js
  • production mode will minify and do optimizations 生产模式将最小化并进行优化

Your config seems to be right, but Webpack can't find it and assumes the default entry, thus your error Can't resolve './src' . 您的配置似乎正确,但是Webpack找不到它并采用默认条目,因此您的错误Can't resolve './src'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根目录外的 webpack /src - webpack /src outside root directory Webpack“找不到模块:错误:无法解析'./src/'” - Webpack "Module not found: Error: Can't resolve './src/'" 正在安装webpack-找不到入口模块。 无法解析“文件”或“目录” - Installing webpack - Entry module not found. cannot resolve 'file' or 'directory' Vue-CLI 3:如何在 webpack 包中包含 /src 目录外部的 LESS 文件? - Vue-CLI 3: How to include LESS files from outside of /src directory in webpack bundle? 找不到主模块中的 WEBPACK5 错误:错误:无法解析“./src” - WEBPACK5 ERROR in main Module not found: Error: Can't resolve './src' 未找到模块错误:您尝试导入项目 src/ 目录之外的内容。 不支持 src/ 之外的相对导入 - Module not found Error: You attempted to import which falls outside of the project src/ directory. Relative imports outside of src/ are not supported 未找到模块:您尝试导入项目 src/ 目录之外的模块。 不支持 src/ 之外的相对导入 - Module not found: You attempted to import which falls outside of the project src/ directory. Relative imports outside of src/ are not supported 使用Webpack在HTML中通过src加载图像 - Loading images by src in html with webpack webpack错误无法解决“ ./src” - webpack error cant resolve './src' 在 Webpack4 中设置 ./src 的路径? - Setting path to ./src in Webpack4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM