[英]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.