自从我看到解决方案[here] [1]的错误后,将'babel/register'
更新为babel-register
,我收到以下错误:
.../app-server.js: Unexpected token (53:62)
// Get React markup
> 53 | const reactMarkup = ReactDOMServer.renderToStaticMarkup(<RoutingContext {...renderProps} />)
| ^
54 | res.locals.reactMarkup = reactMarkup
55 |
这真的很烦人,因为它以前在工作。最近react-router
有什么变化吗?我觉得我在npm或babel中更新了一些东西,它打破了另一个。这是一个创建简单应用程序的无尽过程。上面的语法有什么问题?
WEBPACK文件
// webpack.config.js
const webpack = require('webpack')
//copy files
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const path = require('path');
const PATHS = {
app: path.join(__dirname, './app-client.js'),
build: path.join(__dirname, './public'),
fonts: path.join(__dirname, './fonts'),
cssLoc: path.join(__dirname, './styles'),
imagesLoc: path.join(__dirname, './images')
};
if(process.env.NODE_ENV === 'development'){
var loaders = ['react-hot','babel']
} else {
var loaders = ['babel']
}
module.exports = {
devtool: 'eval',
resolve: {
extensions: ['', '.js', '.jsx']
},
//bundle app from here
entry: {
app: PATHS.app
},
output: {
path: PATHS.build,
filename: 'bundle.js',
publicPath: PATHS.build
},
devServer: {
// This is required for webpack-dev-server. The path should
// be an absolute path to your build destination.
outputPath: PATHS.build
},
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel-loader?presets[]=es2015,presets[]=stage-0, presets[]=stage-1,presets[]=stage-2,presets[]=react,plugins[]=transform-runtime'],
exclude: /node_modules/
},
{ test: /\.scss$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract('style', 'css!sass?sourceMap')
},
{
test: /\.(jpg|jpeg|gif|png|svg)$/,
exclude: /node_modules/,
include: PATHS.imagesLoc,
loader: "file-loader?name=img/[name].[ext]"
},
// Font Definitions
{ test: /\.svg$/, loader: 'url?limit=65000&mimetype=image/svg+xml&name=fonts/[name].[ext]' },
{ test: /\.woff$/, loader: 'url?limit=65000&mimetype=application/font-woff&name=fonts/[name].[ext]' },
{ test: /\.woff2$/, loader: 'url?limit=65000&mimetype=application/font-woff2&name=fonts/[name].[ext]' },
{ test: /\.[ot]tf$/, loader: 'url?limit=65000&mimetype=application/octet-stream&name=fonts/[name].[ext]' },
{ test: /\.eot$/, loader: 'url?limit=65000&mimetype=application/vnd.ms-fontobject&name=fonts/[name].[ext]' }
]},
plugins: [
new webpack.DefinePlugin({
'process.env.COSMIC_BUCKET': JSON.stringify(process.env.COSMIC_BUCKET)
}),
new CopyWebpackPlugin([
{ from: 'images/', to: 'img/' },
{ from: 'fonts/', to: 'fonts/' }
]),
new ExtractTextPlugin("css/custom.css")
]
};