【发布时间】:2018-07-31 12:29:49
【问题描述】:
所以在我的第一个 ReactJS 教程中,我使用的是 Ubuntu VM,并记得遇到这个问题是因为我忘记安装 react 和 react-dom 依赖项。我现在在 Windows 上,确保安装了所有东西,我得到了同样的错误:
对于我的 package.json,我有这个:
{
"name": "github-battle",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"dependencies": {},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.9",
"html-webpack-plugin": "^2.30.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"style-loader": "^0.20.2",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.1"
},
"scripts": {
"create": "webpack"
},
"author": "",
"license": "ISC"
}
对于我的 webpack.config.js
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './app/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index_bundle.js',
publicPath: '/'
},
module: {
rules: [
{ test: /\.(js)$/, use: 'babel-loader' },
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
]
},
devServer: {
historyApiFallback: true,
},
plugins: [
new HtmlWebpackPlugin({
template: 'app/index.html'
})
]
};
index.js
var React = require('react');
var ReactDOM = require('react-dom');
require('./index.css');
class App extends React.Component{
render(){
return(
<div>Hello World</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));
在 Windows 中有什么我必须做的不同的事情吗?
【问题讨论】:
-
您应该仔细检查换行符类型。您应该在 Windows 中更改回 CR LR,在 Linux 中更改为 LF。使用任何代码编辑器(例如 Notepad++)来更改它。
-
问题是我做了一个全新的项目,我没有从我的 Linux VM 复制任何东西
-
不。即使您在 Windows 中创建文件,仍然有可能换行模式不正确。
-
我使用的是 Notepad++,它说行尾格式是 Windows,编码是 UTF-8
标签: javascript html json reactjs webpack