ons-navigator:错误:模块解析失败:意外令牌(330:6)

问题描述 投票:0回答:1

如何解决此错误?使用“ 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'
            ]
          }
        }]
      }
...
reactjs webpack onsen-ui onsen-ui2
1个回答
0
投票

此错误的原因是不正确导入Navigator组件。错误:import Navigator from "react-onsenui/src/components/Navigator";正确:import {Navigator} from 'react-onsenui';

IDE强制自动导入后,添加了错误的导入。

© www.soinside.com 2019 - 2024. All rights reserved.