gpt4 book ai didi

webpack - 即使使用 babel-loader,模块解析也因 webpack 失败并使用react

转载 作者:行者123 更新时间:2023-12-04 23:18:17 26 4
gpt4 key购买 nike

我正在尝试将 webpack 与 react 一起使用,但出现此错误:

./app/main.js 中的错误

Module parse failed: /Users/me/app/main.js Line 2: Unexpected token
You may need an appropriate loader to handle this file type.
| //npm
| import React from 'react';

这是感兴趣的 webpack 配置部分:
test: /\.jsx?$/,
include: path.join(__dirname, 'src'),
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']

和 package.json:
"devDependencies": {
"autoprefixer-loader": "^3.1.0",
"babel-core": "^6.1.20",
"babel-loader": "^6.1.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"jest": "^0.1.40",
"webpack": "^1.12.4",
"webpack-dev-server": "^1.12.1",
"css-loader": "^0.22.0",
"style-loader": "^0.13.0"
},
"dependencies": {
"babel-polyfill": "^6.1.19",
"history": "^1.17.0",
"react": "^0.14.2",
"react-dom": "^0.14.2",
"react-mdl": "^1.0.4",
"react-router": "^1.0.2"
}

最佳答案

查看错误消息中的路径

Module parse failed: /Users/me/app/main.js Line 2: Unexpected token



似乎该模块不在 src 内文件夹。但是,您明确指定只有 path.join(__dirname, 'src') 中的模块应该通过 babel loader。

调整 include这样它也将包括 main.js .

关于webpack - 即使使用 babel-loader,模块解析也因 webpack 失败并使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34436690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com