webpack - tsx 文件宽度 babel-loader 错误
webpack - tsx files width babel-loader error
当我使用 babel-loader 编译我的 react 项目时,告诉我解析失败。
这是我的 webpack.config.js 文件。
module: {
rules: [
{
test: /^\.([jt])sx$/,
include: path.resolve(__dirname, 'src'),
use: [
{
loader: "babel-loder",
options: {
"presets": [
["@babel/preset-env"],
"@babel/preset-react",
["@babel/preset-typescript"]
]
}
}
]
}
]
}
当我 运行 webpack cli 时,错误如下:
Module parse failed: Unexpected token (3:7)
You may need an appropriate loader to handle this file type, currently no loaders are configured to
process this file. See https://webpack.js.org/concepts#loaders
| import React, {PureComponent} from 'react';
> export interface ILazyImageProps extends React.DetailsHTMLAttributes<HTMLImageElement>
看起来 "export interface" 抛出了错误。
但是用babel cli就可以了。
谁能告诉我为什么?
此配置应该对您有帮助:
webpack.config.js
module.exports = {
// Your configuration of entry and output
module: {
rules: [
{
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: [
"@babel/env",
"@babel/react",
"@babel/typescript"
]
}
}
]
}
]
}
};
当我使用 babel-loader 编译我的 react 项目时,告诉我解析失败。 这是我的 webpack.config.js 文件。
module: {
rules: [
{
test: /^\.([jt])sx$/,
include: path.resolve(__dirname, 'src'),
use: [
{
loader: "babel-loder",
options: {
"presets": [
["@babel/preset-env"],
"@babel/preset-react",
["@babel/preset-typescript"]
]
}
}
]
}
]
}
当我 运行 webpack cli 时,错误如下:
Module parse failed: Unexpected token (3:7)
You may need an appropriate loader to handle this file type, currently no loaders are configured to
process this file. See https://webpack.js.org/concepts#loaders
| import React, {PureComponent} from 'react';
> export interface ILazyImageProps extends React.DetailsHTMLAttributes<HTMLImageElement>
看起来 "export interface" 抛出了错误。
但是用babel cli就可以了。 谁能告诉我为什么?
此配置应该对您有帮助:
webpack.config.js
module.exports = {
// Your configuration of entry and output
module: {
rules: [
{
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: [
"@babel/env",
"@babel/react",
"@babel/typescript"
]
}
}
]
}
]
}
};