无法解析文件或目录webpack

时间:2016-02-21 06:00:37

标签: webpack

我从webpack收到连续错误。我对此很新。但我不知道为什么在运行webpack命令时没有找到src里面的main.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;

这是我的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"
}

错误详情

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

我知道这是Webpack Error的重复问题。但是这个问题目前尚未解决。

我无法在这里找到问题,因为package.json似乎是有效的,并且没有丢失的逗号或任何我似乎犯了错误的东西。

1 个答案:

答案 0 :(得分:0)

这可能是由于多种原因造成的。确定问题的最佳方法是,如果您单独运行webpack 1/2,请尝试以下两个命令,然后使用该代码段:

webpack --display-error-details

如果您正在运行webpack dev服务器,请使用代码段:

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

这将在控制台中提供详细的错误报告

此外,如果您在条目文件名中提供任何可能也存在问题的空间