. Advertisement .
..3..
. Advertisement .
..4..
I am trying to write a javascript that returns the invalid answer. I don’t know where the incorrect command is in the “you may need an appropriate loader to handle this file type.”. My detail is:
You may need an appropriate loader to handle this file type.
| import React from 'react';
| /*
| import { render } from 'react-dom'
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './index',
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/dist/'
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
}
}
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var config = require('./webpack.config');
var express = require('express');
var app = express();
var port = 3000;
var compiler = webpack(config);
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.listen(port, function(err) {
console.log('Server started on http://localhost:%s', port);
});
And I end up with the warning message:
You may need an appropriate loader to handle this file type.
| import React from 'react';
| /*
| import { render } from 'react-dom'
Pls, suggest the best answer to fix it.
The cause: Because of new updates and changes overtime, your version compatibility started causing problems with configuration.
Solution:
es2015
preset need to be installed in your configuration. You can set up it by doing this suggestion:After that is
babel-loader
configuration:You must have the ES2015 babel preset.
An example package.json devDependencies is:
Now, configure babelloader within your webpack configuration:
Add a .babelrc to the root folder of your project, where the node module are: