【问题标题】:ons-navigator: Error: Module parse failed: Unexpected token (330:6)ons-navigator:错误:模块解析失败:意外令牌 (330:6)
【发布时间】:2020-02-27 05:58:15
【问题描述】:

如何解决这个错误?使用“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'
            ]
          }
        }]
      }
...

【问题讨论】:

  • 欢迎使用 StackOverflow,您能否提供不起作用的组件?另外,您使用的是哪个版本的 Webpack?在 Webpack 7 中,一些预设和插件已经更新。

标签: reactjs webpack onsen-ui onsen-ui2


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2020-11-20
    • 2021-11-26
    • 2023-03-27
    • 2019-02-15
    • 1970-01-01
    • 2021-04-26
    • 2021-05-01
    • 2020-11-16
    • 2021-05-11
    相关资源
    最近更新 更多