[英]ons-navigator: Error: Module parse failed: Unexpected token (330:6)
如何修復此錯誤? 使用“react-onsenui”庫中的 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'
]
}
}]
}
...
此錯誤的原因是導航器組件的導入不正確。
錯誤: import Navigator from "react-onsenui/src/components/Navigator";
正確: import {Navigator} from 'react-onsenui';
IDE 強制自動導入后添加了錯誤的導入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.