解析JSON babel失败时出错

nhaq1z21  于 2023-02-14  发布在  Babel
关注(0)|答案(3)|浏览(200)

当我运行gulp时,解析JSON时出现错误:

Syntax Error 'C:\Path\main.js' Error while parsing JSON
at: 98
text: '{\r\n   "development":

"text"在命令行中被截断。我尝试将输出通过管道传输到文件,但失败了,因为错误没有显示在文件中:
Powershell命令
gulp | Out-File C:\temp.txt -width 120
package.json

{
  "name": "helloreact",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "dependencies": {
    "babel": "^6.5.1",
    "babel-plugin-react-transform": "^2.0.0",
    "babel-preset-react": "^6.3.13",
    "babelify": "^7.2.0",
    "bootstrap": "^3.3.5",
    "flux": "^2.0.3",
    "gulp": "^3.9.0",
    "gulp-concat": "^2.6.0",
    "gulp-connect": "^2.2.0",
    "gulp-eslint": "^1.1.1",
    "gulp-open": "^1.0.0",
    "gulp-sourcemaps": "^1.6.0",
    "jquery": "^2.1.4",
    "jquery-csv": "^0.8.1",
    "lodash": "^4.0.1",
    "object-assign": "^4.0.1",
    "react": "^0.13.3",
    "react-router": "^0.13.3",
    "react-tools": "^0.10.0",
    "react-transform": "0.0.3",
    "reactify": "^1.1.1",
    "redbox-react": "^1.2.2",
    "toastr": "^2.1.0",
    "vinyl-source-stream": "^1.1.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

巴伯尔

{
  "env": {
    "development": {
      "plugins": ["react-transform"],
      }
    }
  }
}

我的 Gulp 任务使用babelify

gulp.task('js', function(){
  browserify(config.paths.mainJs,  { debug: true })
      .transform(babel, {presets: ["react"]})
      .transform(reactify)
      .bundle()
      .on('error', console.error.bind(console))
      .pipe(source('bundle.js'))
      .pipe(sourcemaps.init({ loadMaps: true }))
      .pipe(sourcemaps.write('./'))//TODO: not sure if this syntax is correct
      .pipe(gulp.dest(config.paths.dist + '/scripts'))
      .pipe(connect.reload())
});
6rqinv9w

6rqinv9w1#

尝试删除bablerc中多余的逗号

{
  "env": {
    "development": {
      "plugins": ["react-transform"]
      }
    }
  }
}
zf2sa74q

zf2sa74q2#

我的情况是:react + redux项目。我的起源。babelrc内容是

{
  "presets" : ["es2015","react"]
}

我从预设和webpack工作中删除了“es2015”

szqfcxe2

szqfcxe23#

将其更改为{ 'presets':在.babelrc文件中的['@ babel/env']},为我修复了它。

相关问题