当前位置: 首页 > 知识库问答 >
问题:

模块分析失败:意外的令牌。您可能需要适当的加载程序来处理此文件类型

卫寒
2023-03-14

我得到下面的错误,我不明白为什么我认为应该有一些与巴贝尔。我使用web开发服务器和babel。它在反应。

ERROR in ./App.js 188:13
Module parse failed: Unexpected token (188:13)
You may need an appropriate loader to handle this file type.
| //console.log(filter);
| if(isHomePage)
| return
| return (
| <div className={'App ${isDetailPage ? 'detail-page' : 'landing-page'} '}

@ ./main.js 1:0-27
@ multi (webpack)-dev-server/client?http://localhost:8080 ./main.js

ERROR in ./Home.js 34:8
Module parse failed: Unexpected token (34:8)
You may need an appropriate loader to handle this file type.
| render() {
| return (
| <div className={App}>
| hello
|
@ ./main.js 2:0-29
@ multi (webpack)-dev-server/client?http://localhost:8080 ./main.js
i ?wdm?: Failed to compile.

我的Webconfig文件如下所示:

var path = require('path');
var webpack = require('webpack');

module.exports = {
    entry: './main.js',
    output: { path: __dirname, filename: 'bundle.js' },
    module: {
        rules: [
            {
                test: /.jsx?$/,
                include: [
                    path.resolve(__dirname, 'path/to/imported/file/dir')
                ],
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015', 'react']
                }
            }
        ]
    },
}

我的package.json文件如下所示:

"dependencies": {
    "missing": "0.0.1",
    "react": "^0.14.7",
    "react-dom": "^0.14.7",
    "react-router-dom": "^4.3.1",
    "webpack-dev-server": "^3.1.10"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "webpack": "^4.27.1",
    "webpack-cli": "^3.1.2"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC"
}

我错过了什么?这与path.resolve有关吗?

共有1个答案

蒋俊
2023-03-14

我也遇到了同样的问题,在我的例子中,问题与正则表达式有关。正则表达式的定义是错误的。我建议您检查main.js中的任何正则表达式。

 类似资料: