gpt4 book ai didi

webpack - 错误: Can't resolve 'babel-loader'

转载 作者:行者123 更新时间:2023-12-03 09:07:34 24 4
gpt4 key购买 nike

我收到这个错误,你能帮帮我吗。以下是我的 webpack.config 和 package.JSON 文件。我的服务器工作正常,但 webpack 不行。我全局安装了 Webpack,但这并没有解决这个问题。

===webpack.config文件===

var path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './src/app.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'public')
},
watch: true,
module: {
loaders: [
{
test:/\.js$/,
exclude:/node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-1']
}
}

]
}

===Package.JSON 文件===

{
"name": "reduxApp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^3.5.5"
},
"dependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-1": "^6.24.1",
"express": "^4.15.4",
"loader": "^2.1.1",
"redux": "^3.7.2"
}
}

最佳答案

此包允许使用 Babel 和 webpack 转译 JavaScript 文件。

此任务所需的只是添加实际的加载程序和环境预设作为开发依赖项:npm install -D babel-loader babel-preset-env

在你的 webpack 配置对象中,你需要将 babel-loader 添加到模块列表中,如下所示:

模块:{
规则:[
{
测试:/\.js$/,
排除:/(node_modules|bower_components)/,
使用: {
加载器:'巴别塔加载器',
选项: {
预设:['env']
}
}
}
]
}

关于webpack - 错误: Can't resolve 'babel-loader' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45806392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com