Reactjs ons导航器:错误:模块解析失败:意外令牌(330:6)
如何修复此错误?使用“react onsenui”库中的导航器组件时会发生此错误Reactjs ons导航器:错误:模块解析失败:意外令牌(330:6),reactjs,webpack,onsen-ui,onsen-ui2,Reactjs,Webpack,Onsen Ui,Onsen Ui2,如何修复此错误?使用“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#l
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>
此错误的原因是导航器组件的导入不正确。
错误:
从“react onsenui/src/components/Navigator”导入导航器代码>
正确:从'react onsenui'导入{Navigator}代码>
IDE强制自动导入后添加了错误的导入。欢迎使用StackOverflow,您能提供不起作用的组件吗?另外,您使用的是哪个版本的网页包?在Webpack 7中,一些预设和插件已经更新。
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'
]
}
}]
}
...