javascript - 出现错误“您可能需要适当的加载程序来处理此文件类型。” 使用 Webpack 编译 ES6 资产时
问题描述
我使用带有 Babel 的 Webpack 在我的 Nodejs 应用程序中编译 ES6 资产,但我收到以下错误消息:
You may need an appropriate loader to handle this file type.
|
| const addMrnObj = {
| ...jsonObj,
| optionalMrn: optionalMrn
| };
@ ./config/eventSource/eventSourceCall.js 5:18-40
@ ./src/app.js
@ multi ./src/app.js
我正在使用 2.2.1 版的 Webpack 和 6.22.0 版的 babel-preset-es2015
下面是我的 babel.rc 配置
{
"presets": [
"es2015"
],
"plugins": [
"transform-flow-strip-types",
"transform-object-rest-spread",
"transform-class-properties",
"syntax-class-properties"
]
}
这是我的 Webpack 配置
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var BabiliPlugin = require('babili-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var BUILD_DIR = path.resolve(__dirname, 'dist');
var APP_DIR = path.resolve(__dirname, 'src');
var config = {
entry: [
APP_DIR + '/app.js',
],
target: 'node',
output: {
path: BUILD_DIR,
filename: 'backend.js'
},
plugins: [
new BabiliPlugin(),
new CopyWebpackPlugin([{
from: './config',
to: 'config'
}])
],
module: {
loaders: [
{
test: /\.js?/,
exclude: /node_modules/,
include: [ APP_DIR ],
loader: 'babel-loader'
}
]
}
};
module.exports = config;
有人可以指出我需要进行哪些其他更改才能解决此错误。
解决方案
尝试在预设下的 babel.rc 文件中添加“@babel/preset-env”(也安装预设)。而且你的语法也是错误的,这应该是
{
"presets": ["@babel/preset-es2015"]
}
并且文件名应该是 .babelrc 而不是 babel.rc
推荐阅读
- java - Java:数据同步问题
- r - 如何在 rgl 图中去除/减少球体的光泽
- python - 无法使用 Python 通过 socks5 代理发送请求
- amazon-web-services - 直接或通过 AWS Glue 数据目录将 Redshift Spectrum/AWS EMR 与 Hudi 连接
- helmfile - Helmfile - “需要”关键字没有效果
- ssh - 使用 ssh-copy-id 复制您的公钥
- android - 有谁知道 Android Studio 无法识别布局属性的常见原因?
- authentication - laravel 8.x auth 使用不同的表和不同的保护
- ansible - 使用 Ansible 设置一对相互依赖的服务器
- ocaml - 如何命名 OCaml 变体中的字段?