如何解决此错误?使用“ react-onsenui”库中的导航器组件时,会发生此错误。
Error: Module parse failed: Unexpected token (330:6)
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
|
| return (
> <ons-navigator { ...attrs } ref={(navi) => { this._navi = navi; }}>
| {pages}
| </ons-navigator>
Webpack.config.js代码的一部分:
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: path.resolve(__dirname, 'src'),
use: [{
loader: 'babel-loader',
options: {
presets: ['react', 'env'],
plugins: [
'react-hot-loader/babel',
'transform-class-properties',
'transform-object-rest-spread'
]
}
}]
}
...
此错误的原因是不正确导入Navigator组件。错误:import Navigator from "react-onsenui/src/components/Navigator";
正确:import {Navigator} from 'react-onsenui';
IDE强制自动导入后,添加了错误的导入。