2017-04-19 76 views
0

目前我自我教导自己反应并试图设置一个开始框架。我在下面的错误在我的命令行中运行npm start后:7777:npm开始不与webpack一起使用反应

~/projects/reactApp » webpack --display-error-details   [email protected] 
Hash: 94c3df302d8dd2990ab8 
Version: webpack 2.4.1 
Time: 37ms 

ERROR in Entry module not found: Error: Can't resolve './main.js' in '/Users/Dustin/projects/reactApp' 
resolve './main.js' in '/Users/Dustin/projects/reactApp' 
    using description file: /Users/Dustin/projects/reactApp/package.json (relative path: .) 
    Field 'browser' doesn't contain a valid alias configuration 
    after using description file: /Users/Dustin/projects/reactApp/package.json (relative path: .) 
    using description file: /Users/Dustin/projects/reactApp/package.json (relative path: ./main.js) 
     as directory 
     /Users/Dustin/projects/reactApp/main.js doesn't exist 
     no extension 
     Field 'browser' doesn't contain a valid alias configuration 
     /Users/Dustin/projects/reactApp/main.js doesn't exist 
     .js 
     Field 'browser' doesn't contain a valid alias configuration 
     /Users/Dustin/projects/reactApp/main.js.js doesn't exist 
     .json 
     Field 'browser' doesn't contain a valid alias configuration 
     /Users/Dustin/projects/reactApp/main.js.json doesn't exist 
------------------------------------------------------------ 
~/projects/reactApp » 

巧合的是我试图加载本地主机时,得到同样的错误。我不是很熟悉webpack,并且好奇我做错了什么。 Webpack在显示错误方面并不是很出色,但我已经设法解决了至此为止的其他错误。

webpack.config.js

var config = { 
    entry: './main.js', 

    output: { 
    path: '/', 
    filename: 'index.js' 
    }, 

    devServer: { 
    inline: true, 
    port: 7777 
    }, 

    module: { 
    loaders: [{ 
     test: /\.jsx?$/, 
     exclude: /node_modules/, 
     loader: 'babel', 

     query: { 
     presets: ['es2015', 'react'] 
     } 
    }] 
    } 

} 

module.exports = config; 

的package.json

{ 
    "name": "reactapp", 
    "version": "1.0.0", 
    "description": "first React app following tutorial", 
    "main": "index.js", 
    "scripts": { 
    "start": "webpack-dev-server --hot" 
    }, 
    "repository": { 
    "type": "git", 
    "url": "reactApp" 
    }, 
    "keywords": [ 
    "react" 
    ], 
    "author": "Dustin Waggoner", 
    "license": "ISC", 
    "dependencies": { 
    "react": "^15.5.4", 
    "react-dom": "^15.5.4" 
    }, 
    "devDependencies": { 
    "babel-plugin-transform-react-jsx": "^6.24.1" 
    } 
} 

我认为这是一个路径问题,而是试图几个不同的选项来纠正。谢谢你的帮助。

+0

您的'main.js'在哪里?您将该条目定义为'./main.js',这意味着您的'/ Users/Dustin/projects/reactApp'文件位于'webpack.config.js'的相同目录中。显然它不在那里。如果它在'src/main.js'中,你可以使用'entry:'./src/main.js''。这个错误对我来说很清楚。 –

回答

0

试试这个。 解决方案在您使用非默认设置时是必需的。

Here is the documents for webpack

var config = { 
    entry: './main.js', 

    output: { 
    path: '/', 
    filename: 'index.js' 
    }, 
    resolve: { 
    extensions: ['', '.js', '.jsx'] 
    }, 
    devServer: { 
    inline: true, 
    port: 7777 
    }, 

    module: { 
    loaders: [{ 
     test: /\.jsx?$/, 
     exclude: /node_modules/, 
     loader: 'babel', 

     query: { 
     presets: ['es2015', 'react'] 
     } 
    }] 
    } 

} 

module.exports = config; 
+0

感谢您的帮助。你的想法现在给了我以下错误:'无效的配置对象。 Webpack已使用与API模式不匹配的配置对象进行初始化。 - configuration.resolve.extensions [0]不应该是空的。' – DustinRW

+0

探讨了“https://github.com/webpack/webpack/issues/3043”,它指示从扩展中删除''''并且返回到原始问题 – DustinRW

+0

我们有不同版本的webpack,如果您不知道,请将项目上传到github。让我们试图找出它。 – TonyY