我是新来的人 我在我的React应用中将Webpack与babel loader一起使用
在我更改机器之前,我的项目运行良好,我已经复制了除node_modules
(已安装npm install
以外的所有文件)
当我尝试运行或构建项目时,这会在旧计算机上正确运行的同时给我错误
import React from 'react';
import ReactDOM from 'react-dom';
import App from './app.js';
import {HashRouter,Route,Switch} from 'react-router-dom';
import '../node_modules/bootstrap/dist/css/bootstrap.css'
ReactDOM.render(
<HashRouter>
<App />
</HashRouter>
, document.getElementById('app'));
Rs-MacBook-Pro:rd $ npm start
boilerplate-intranet@1.0.0开始/ Users / rd / Documents / intra webpack-dev-server --open --mode开发
ℹwds」:项目运行在http://localhost:8080/「wds」:webpack 输出来自/ wwds」:提供非webpack的内容 来自/ Users / rd / Documents / intra / public「wds」:404会回退到 /index.html wdm」:等到包完成后:/ wdm」:哈希: 53cc551e031b5ed39d70版本:webpack 4.19.1时间:3596ms构建于: 2018-09-21 12:44:47 资产大小块块名称bundle.js 836 KiB main [emited] main Entrypoint main = bundle.js [./node_modules/ansi-html/index.js] 4.16 KiB {main} [内置] [./node_modules/ansi-regex/index.js] 135个字节{main} [内置] [./node_modules/loglevel/lib/loglevel.js] 7.68 KiB {main} [内置] [./node_modules/punycode/punycode.js] 14.3 KiB {main} [内置] [./node_modules/url/url.js] 22.8 KiB {main} [内置] [0]多 (webpack)-dev-server / client?http://localhost:8080 ./src/index.js 40 字节数{main} [内置] [./node_modules/sockjs-client/dist/sockjs.js] 177 KiB {main} [内置] [./node_modules/strip-ansi/index.js] 161字节 {main} [内置] [./node_modules/url/util.js] 314个字节{main} [内置] [./node_modules/webpack-dev-server/client/index.js?http://localhost:8080] (webpack)-dev-server / client?http://localhost:8080 7.78 KiB {main} [内置] [./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server / client / overlay.js 3.58 KiB {main} [内置] [./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server / client / socket.js 1.05 KiB {main} [内置] [./node_modules/webpack/hot sync ^。/ log $](webpack)/ hot sync 非递归^。/ log $ 170字节{main} [内置] [./node_modules/webpack/hot/emitter.js](webpack)/hot/emitter.js 75 字节{主要} [内置] [./src/index.js] 761字节{主要} [内置] [失败] [1个错误] + 11个隐藏模块
./src/index.js中的ERROR模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):语法错误:意外 令牌(9:4)
7 | 8 | ReactDOM.render(
9 | | ^ 10 | 11 | 12 |
@多(webpack)-开发服务器/客户端?http://localhost:8080 ./src/index.js main 1「wdm」:编译失败。
答案 0 :(得分:0)
某些版本的babel-core和babel-loader不兼容,如果您不介意使用特定版本,请尝试将它们更新为最新版本
npm install -D babel-loader @babel/core @babel/preset-env webpack