admin管理员组文章数量:1334157
I have the following code (es6 spread Attribute):
return {...state, name: action.payload};
The error thrown is: You may need an appropriate loader to handle this file type.
package.json
What else do I need to install in order to make this work. All the other ES6 is working but the spread attribute isn't.
webpack.config.js
I have the following code (es6 spread Attribute):
return {...state, name: action.payload};
The error thrown is: You may need an appropriate loader to handle this file type.
package.json
What else do I need to install in order to make this work. All the other ES6 is working but the spread attribute isn't.
webpack.config.js
Share Improve this question edited Jun 7, 2018 at 6:17 EugenSunic asked Feb 28, 2017 at 11:03 EugenSunicEugenSunic 13.7k15 gold badges66 silver badges95 bronze badges 2- Can you share your webpack configuration? There you will see the loaders that may be needed. – Deividas Commented Feb 28, 2017 at 11:04
- So package.json isn't enough... I have no loaders whatsoever in my webpack.config.js I' ll ad them now – EugenSunic Commented Feb 28, 2017 at 11:05
3 Answers
Reset to default 3To use ecmascript-6
you need to (1) add .babelrc
file with the following presets
{
"presets": [ "es2015" ]
}
es2015
is the particular one you need.
And then (2) configure your webpack to include
module.exports = {
...,
loaders : [
{ test: /\.js$/, exclude: /(node_modules)/, loader: 'babel-loader' }
]
}
You need have configured babel-loader for js files to transpile
webpack config snippet :
{
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader'
]
}
Inside module rules.
Also add .babelrc
file in your projects home directory with below contents
{
"presets" : [
"latest"
]
}
Installing loaders via npm isn't enough. You have to configure that loaders in your webpack.
Add following in your webpack.config.js
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_ponents)/,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
}
]
Using loaders in webpack
Code above means that, whenever it will find any file that matches \.js$
pattern (files that ends with .js), babel-loader will be used. (You have already installed babel-loader into your dependencies.
You can also use loader: 'babel'
instead of `loader: 'babel-loader'. It's the same.
本文标签: javascriptYou may need an appropriate loader to handle this file typeerrorStack Overflow
版权声明:本文标题:javascript - You may need an appropriate loader to handle this file type-error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742365003a2461111.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论