ons-navigator: Error: Module parse failed: Unexpected token (330:6)
ons-navigator: Error: Module parse failed: Unexpected token (330:6)
如何解决这个错误?使用来自 'react-onsenui' lib.
的 Navigator 组件时会发生此错误
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强制自动导入后添加了错误的导入。
如何解决这个错误?使用来自 'react-onsenui' lib.
的 Navigator 组件时会发生此错误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强制自动导入后添加了错误的导入。