gpt4 book ai didi

javascript - 带有 babel-loader 的 Webpack 无法识别 import 关键字

转载 作者:IT王子 更新时间:2023-10-29 03:21:37 25 4
gpt4 key购买 nike

我有这个webpack.config.js:

module.exports = {
entry: './src/admin/client/index.jsx',
output: {
filename: './src/admin/client/static/js/app.js'
},
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
query: {
optional: ['runtime']
}
}
],
resolve: {
extensions: ['', '.js', '.jsx']
}
};

...但我仍然收到此错误:

$ webpack -vHash: 2a9a40224beb025cb433Version: webpack 1.10.5Time: 44ms   [0] ./src/admin/client/index.jsx 0 bytes [built] [failed]ERROR in ./src/admin/client/index.jsxModule parse failed: /project/src/admin/client/index.jsx Line 1: Unexpected reserved wordYou may need an appropriate loader to handle this file type.| import React from 'react';| import AdminInterface from './components/AdminInterface';

I have:

  • Installed webpack globally and locally
  • Installed babel-loader, babel-core, and babel-runtime
  • Installed babel-loader globally, just in case

Why the hell is webpack seemingly ignoring babel-loader? Or does babel-loader not work with modules?

Update:

It looks like babel handles the input file just fine. When I run:

./node_modules/babel/bin/babel.js ./src/admin/client/index.jsx

...它按预期输出 ES5。因此,在我看来,webpack 没有正确加载 babel-loader

最佳答案

这看起来像是操作失误的情况。我的 webpack.config.js 结构不正确。具体来说,我需要将加载器详细信息放在 module 部分中:

module.exports = {
entry: './src/admin/client/index.jsx',
output: {
filename: './src/admin/client/static/js/app.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
query: {
optional: ['runtime']
}
}
],
resolve: {
extensions: ['', '.js', '.jsx']
}
}
};

关于javascript - 带有 babel-loader 的 Webpack 无法识别 import 关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31799558/

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