移动到另一台机器后 React 项目出现错误
我是 React 新手 我在我的 React 应用中使用带有 Babel 加载器的 Webpack
我的项目运行良好,直到我更换了机器,我复制了除
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:intra rd$ npm start
[email protected] start /Users/rd/Documents/intra webpack-dev-server --open --mode development
ℹ 「wds」: Project is running at http://localhost:8080/ ℹ 「wds」: webpack output is served from / ℹ 「wds」: Content not from webpack is served from /Users/rd/Documents/intra/public ℹ 「wds」: 404s will fallback to /index.html ℹ 「wdm」: wait until bundle finished: / ✖ 「wdm」: Hash: 53cc551e031b5ed39d70 Version: webpack 4.19.1 Time: 3596ms Built at: 2018-09-21 12:44:47 Asset Size Chunks Chunk Names bundle.js 836 KiB main [emitted] main Entrypoint main = bundle.js [./node_modules/ansi-html/index.js] 4.16 KiB {main} [built] [./node_modules/ansi-regex/index.js] 135 bytes {main} [built] [./node_modules/loglevel/lib/loglevel.js] 7.68 KiB {main} [built] [./node_modules/punycode/punycode.js] 14.3 KiB {main} [built] [./node_modules/url/url.js] 22.8 KiB {main} [built] [0] multi (webpack)-dev-server/client? http://localhost:8080 ./src/index.js 40 bytes {main} [built] [./node_modules/sockjs-client/dist/sockjs.js] 177 KiB {main} [built] [./node_modules/strip-ansi/index.js] 161 bytes {main} [built] [./node_modules/url/util.js] 314 bytes {main} [built] [./node_modules/webpack-dev-server/client/index.js? http://localhost:8080] (webpack)-dev-server/client? http://localhost:8080 7.78 KiB {main} [built] [./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.58 KiB {main} [built] [./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main} [built] [./node_modules/webpack/hot sync ^./log$] (webpack)/hot sync nonrecursive ^./log$ 170 bytes {main} [built] [./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 75 bytes {main} [built] [./src/index.js] 761 bytes {main} [built] [failed] [1 error] + 11 hidden modules
ERROR in ./src/index.js Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: Unexpected token (9:4)
7 | 8 | ReactDOM.render(
9 | | ^ 10 | 11 | 12 |
@ multi (webpack)-dev-server/client? http://localhost:8080 ./src/index.js main 1 ℹ 「wdm」: Failed to compile.
babel-core 和 babel-loader 的某些版本不兼容,如果你不介意使用特定版本,请尝试将它们更新到最新版本
npm install -D babel-loader @babel/core @babel/preset-env webpack