因此,我一直遇到此阻止程序。不知道为什么这开始或如何解决。关于解决方案有什么想法?我已经尝试了诸如npm update
之类的许多事情,并刷新了node_module文件夹。
节点:v14.4.0 NPM:6.14.4
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"@babel/preset-react": "^7.10.1",
"axios": "^0.19",
"bootstrap": "^4.0.0",
"cross-env": "^7.0",
"jquery": "^3.2",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"resolve-url-loader": "^3.1.0",
"sass": "^1.15.2",
"sass-loader": "^8.0.0",
"vue-template-compiler": "^2.6.11"
},
"dependencies": {
"react-router-dom": "^5.2.0"
}
}
错误:
❯ npm run dev
> @ dev /Users/lucas/Sites/lm
> npm run development
> @ development /Users/lucas/Sites/lm
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
98% after emitting SizeLimitsPlugin
ERROR Failed to compile with 1 errors (<-this is the output npm gives, not a typo) 8:33:35 AM
error in ./resources/js/component/App.js
Syntax Error: SyntaxError: /Users/lucas/Sites/lm/resources/js/component/App.js: Unexpected token (9:12)
7 | render () {
8 | return (
> 9 | <BrowserRouter>
| ^
10 | <div>
11 | <Header />
12 | </div>
App.js:
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import Header from './Header'
class App extends Component {
render () {
return (
<BrowserRouter>
<div>
<Header />
</div>
</BrowserRouter>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'))
更新: 请注意,我已经阅读了下面的链接,建议的解决方案不能解决我遇到的问题:ReactJS: unexpected token '<'
答案 0 :(得分:0)
终于找到适合我的解决方案: https://github.com/babel/babel/issues/8655#issuecomment-419808044
将以下代码段添加到package.json文件中可停止所有意外的(实验性)字符类型错误。
...
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
...