Reactjs React JS:模块生成失败:语法错误:意外标记
我最近想将使用Reactjs React JS:模块生成失败:语法错误:意外标记,reactjs,babeljs,Reactjs,Babeljs,我最近想将使用react create app创建的示例应用程序转移到现有的react项目中 我正在使用react autosuggest库呈现一个简单的搜索栏 将文件导出到现有react项目时,出现以下错误: Module build failed: SyntaxError: Unexpected token (126:11) 124 | } 125 | > 126 | onChange = (event, { newValue }) => {
react create app
创建的示例应用程序转移到现有的react项目中
我正在使用react autosuggest
库呈现一个简单的搜索栏
将文件导出到现有react项目时,出现以下错误:
Module build failed: SyntaxError: Unexpected token (126:11)
124 | }
125 |
> 126 | onChange = (event, { newValue }) => {
| ^
127 | this.setState({
128 | value: newValue
129 | });
BabelLoaderError: SyntaxError: Unexpected token (126:11)
124 | }
125 |
> 126 | onChange = (event, { newValue }) => {
| ^
127 | this.setState({
128 | value: newValue
129 | });
代码是库的一部分
我在项目中看到的唯一区别是它们的devdependency,在package.json中
下面是正在运行的项目的package.json:
{
"name": "autosuggestapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.6.1",
"react-autosuggest": "^9.2.0",
"react-dom": "^15.6.1"
},
"devDependencies": {
"react-scripts": "1.0.7"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
下面是出现错误的一个:
{
"name": "my-app",
"version": "0.0.1",
"description": "my app",
"readme": "./README.md",
"dependencies": {
"babel-polyfill": "6.22.0",
"history": "4.5.1",
"invariant": "2.2.2",
"lodash": "4.17.4",
"node-sass": "^3.13.1",
"query-string": "4.3.1",
"react": "15.4.2",
"react-autosuggest": "^9.3.0",
"react-dom": "15.4.2",
"react-redux": "5.0.2",
"react-tooltip": "3.2.7",
"redux": "3.6.0",
"redux-saga": "0.14.3",
"reselect": "2.5.4",
"sn-http-request": "0.0.16"
},
"devDependencies": {
"babel-cli": "6.22.2",
"babel-core": "6.22.1",
"babel-eslint": "7.1.1",
"babel-loader": "6.2.10",
"babel-preset-es2015": "6.22.0",
"babel-preset-react": "6.22.0",
"babel-preset-stage-3": "6.17.0",
"case-sensitive-paths-webpack-plugin": "1.1.4",
"colors": "1.1.2",
"cross-env": "3.1.3",
"css-loader": "0.26.1",
"eslint": "3.14.1",
"eslint-loader": "1.6.1",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "3.0.2",
"eslint-plugin-react": "6.9.0",
"extract-text-webpack-plugin": "1.0.1",
"fs-extra": "0.30.0",
"glob": "7.1.1",
"jasmine-reporters": "2.2.0",
"jest": "18.1.0",
"jest-cli": "18.1.0",
"lodash-webpack-plugin": "0.11.0",
"mkdirp": "0.5.1",
"moment": "2.15.1",
"node-sass": "4.5.0",
"npm-run-all": "3.1.0",
"q": "1.4.1",
"replacestream": "4.0.2",
"sass-loader": "4.0.2",
"stringify-object": "3.1.0",
"through2": "2.0.1",
"watch": "1.0.1",
"webpack": "1.14.0",
"xml2js": "0.4.17",
"yargs": "6.0.0"
},
"repository": {
"type": "git",
"url": <my project's git url>
},
"engines": {
"node": ">=6.9.0"
},
"jest": {
"testPathIgnorePatterns": [
"/node_modules/",
"/target/"
],
"setupTestFrameworkScriptFile": "./tool/jasmine.env.js"
},
"scripts": {
"clean-target": "babel-node ./tool/build.cleanup.js",
"build:resources": "babel-node ./tool/buildResources.js",
"build:js": "babel-node ./tool/buildJs.js",
"intl": "babel-node ./tool/intl",
"build:intl": "npm-run-all build:resources intl",
"watch": "babel-node ./tool/watcher.js",
"watch-quick": "babel-node ./tool/watcher.js -q",
"prebuild": "npm run clean-target",
"build": "npm-run-all --parallel build:intl build:js",
"build:watch": "npm-run-all build:intl watch",
"start": "npm-run-all prebuild build:resources watch-quick",
"test": "echo 'Do not run jest until fixed'",
"test:watch": "npm run test -- --watch"
}
}
{
“名称”:“我的应用程序”,
“版本”:“0.0.1”,
“说明”:“我的应用程序”,
“自述文件”:“/readme.md”,
“依赖项”:{
“巴别塔polyfill”:“6.22.0”,
“历史”:“4.5.1”,
“不变量”:“2.2.2”,
“lodash”:“4.17.4”,
“节点sass”:“^3.13.1”,
“查询字符串”:“4.3.1”,
“反应”:“15.4.2”,
“反应自动建议”:“^9.3.0”,
“反应dom”:“15.4.2”,
“react redux”:“5.0.2”,
“反应工具提示”:“3.2.7”,
“redux”:“3.6.0”,
“重演传奇”:“0.14.3”,
“重新选择”:“2.5.4”,
“sn http请求”:“0.0.16”
},
“依赖性”:{
“巴别塔cli”:“6.22.2”,
“巴别塔核心”:“6.22.1”,
“babel eslint”:“7.1.1”,
“巴别塔装载机”:“6.2.10”,
“巴别塔-preset-es2015”:“6.22.0”,
“巴别塔预设反应”:“6.22.0”,
“babel-preset-stage-3”:“6.17.0”,
“区分大小写的路径网页包插件”:“1.1.4”,
“颜色”:“1.1.2”,
“交叉环境”:“3.1.3”,
“css加载器”:“0.26.1”,
“eslint”:“3.14.1”,
“eslint加载器”:“1.6.1”,
“eslint插件导入”:“2.2.0”,
“eslint-plugin-jsx-a11y”:“3.0.2”,
“eslint插件反应”:“6.9.0”,
“提取文本网页包插件”:“1.0.1”,
“fs额外”:“0.30.0”,
“全球”:“7.1.1”,
《茉莉花记者》:“2.2.0”,
“笑话”:“18.1.0”,
“jest cli”:“18.1.0”,
“lodash网页包插件”:“0.11.0”,
“mkdirp”:“0.5.1”,
“时刻”:“2.15.1”,
“节点sass”:“4.5.0”,
“npm运行全部”:“3.1.0”,
“q”:“1.4.1”,
“替换流”:“4.0.2”,
“sass加载器”:“4.0.2”,
“字符串化对象”:“3.1.0”,
“通过2”:“2.0.1”,
“手表”:“1.0.1”,
“网页包”:“1.14.0”,
“xml2js”:“0.4.17”,
“yargs”:“6.0.0”
},
“存储库”:{
“类型”:“git”,
“url”:我认为这是因为您使用的是stage-2中的语法,但您使用的是Babel stage-3预设(发布您的package.json
!)
请查看。如果启用第二阶段,您将看到错误消失。谢谢@tay yang-sun