简体   繁体   English

无法解析文件或目录Webpack

[英]Could not resolve file or directory webpack

I am getting continuous error from webpack. 我从webpack收到连续错误。 I am pretty new to this. 我对此很新。 But I have no clue whatsoever why is it no finding the main.js file which is inside src while running webpack command. 但是我不知道为什么为什么在运行webpack命令时找不到src内的main.js文件。

Here is my webpack.config.js 这是我的webpack.config.js

var path = require('path');
var config = {
    entry: {
        main: [
            './src/main.js '
        ]
    },
    output: {
        filename: './public/[name].js'
    },
    module: {
        loaders: [{
            test: /\.jsx?$/, // A regexp to test the require path. accepts either js or jsx,
            exclude: /node_modules/,
            loader: 'babel-loader', // The module to load. "babel" is short for "babel-loader"
            query: {
                presets: ['react', 'es2015']
            }
        }]
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    }
};

module.exports = config;

Here is my package.json 这是我的package.json

{
  "name": "react-quickstart",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "dependencies": {
    "react": "^0.14.7",
    "react-dom": "^0.14.7"
  },
  "devDependencies": {
    "babel-core": "^6.5.2",
    "babel-loader": "^6.2.2",
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0",
    "path": "^0.12.7",
    "webpack": "^1.12.13",
    "webpack-dev-server": "^1.14.1"
  },
  "scripts": {
    "webpack": "./node_modules/webpack/bin/webpack",
    "build": "webpack",
    "dev": "webpack-dev-server --watch-poll --inline --devtool eval --progress --colors --hot --content-base ./"
  },
  "author": "",
  "license": "ISC"
}

Error Details 错误详情

F:\Works\Javascript\react-quickstart>webpack --display-error-details
Hash: 0f797b4ca8770ff88901
Version: webpack 1.12.13
Time: 15ms
           Asset     Size  Chunks             Chunk Names
./public/main.js  1.51 kB       0  [emitted]  main
   [0] multi main 28 bytes {0} [built] [1 error]

ERROR in multi main
Module not found: Error: Cannot resolve 'file' or 'directory' ./src/main.js  in
F:\Works\Javascript\react-quickstart
resolve file
  F:\Works\Javascript\react-quickstart\src\main.js  doesn't exist
  F:\Works\Javascript\react-quickstart\src\main.js .js doesn't exist
  F:\Works\Javascript\react-quickstart\src\main.js .jsx doesn't exist
resolve directory
  F:\Works\Javascript\react-quickstart\src\main.js  doesn't exist (directory def
ault file)
  F:\Works\Javascript\react-quickstart\src\main.js \package.json doesn't exist (
directory description file)
[F:\Works\Javascript\react-quickstart\src\main.js ]
[F:\Works\Javascript\react-quickstart\src\main.js .js]
[F:\Works\Javascript\react-quickstart\src\main.js .jsx]
 @ multi main

I know this is a duplicate issue of Webpack Error . 我知道这是Webpack Error的重复问题。 But this issue is unresolved as of now . 但是到目前为止,这个问题尚未解决。

I am unable to find the issue here as the package.json seems to be valid and there are no missing commas or anything which I seem to have made mistake. 我在这里找不到问题,因为package.json似乎是有效的,并且没有缺少逗号或任何我似乎弄错的东西。

This can be because of multiple reasons. 这可能是由于多种原因。 The best way to identify the exact issue is to tryout the below two commands if you are running webpack 1/2 alone then use the snippet: 找出确切问题的最佳方法是,如果仅运行webpack 1/2,则尝试以下两个命令,然后使用代码段:

webpack --display-error-details

if you are running the webpack dev server then use the snippet: 如果您正在运行webpack开发服务器,则使用代码段:

webpack-dev-server --display-error-details

this would provide a detailed error report in the console 这将在控制台中提供详细的错误报告

Also if you are providing any additional space in the entry file name that could also be a problem 另外,如果您要在条目文件名中提供任何其他空间,这也可能是一个问题

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

相关问题 MultiMain中的错误无法解决目录Webpack问题 - Error in MultiMain could not resolve directory webpack issue Webpack错误 - 无法解析文件或目录 - Webpack Error - Cannot Resolve File or Directory Webpack require()无法解析“文件”或“目录” - Webpack require() Cannot resolve 'file' or 'directory' 具有多个条目的Webpack无法解析“文件”或“目录” - Webpack with multiples entries cannot resolve 'file' or 'directory' Webpack Error无法解析文件或目录(React) - Webpack Error can't resolve file or directory (React) 正在安装webpack-找不到入口模块。 无法解析“文件”或“目录” - Installing webpack - Entry module not found. cannot resolve 'file' or 'directory' webpack 1.12.13 无法解析“文件”或“目录”./img/readme2.png - webpack 1.12.13 Cannot resolve 'file' or 'directory' ./img/readme2.png Webpack错误:找不到模块:错误:无法解析“文件”或“目录” - Webpack Error: Module not found: Error: Cannot resolve 'file' or 'directory' Webpack 和 TypeScript:找不到模块:错误:无法解析“文件”或“目录” - Webpack and TypeScript: Module not found: Error: Cannot resolve 'file' or 'directory' 找不到模块:错误:无法解析“文件”或“目录”(在Webpack中导入sass) - Module not found: Error: Cannot resolve 'file' or 'directory' (import sass in webpack)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM