简体   繁体   中英

ons-navigator: Error: Module parse failed: Unexpected token (330:6)

How to fix this error? This error is occurs when using the Navigator component from 'react-onsenui' lib.

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>

Part of Webpack.config.js code:

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'
            ]
          }
        }]
      }
...

The reason for this error is incorrect import of Navigator component.
Wrong: import Navigator from "react-onsenui/src/components/Navigator";
Correct: import {Navigator} from 'react-onsenui';

The wrong import has been added after force auto-import by IDE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM