【问题标题】:Babel/browserify throws "Error while parsing JSON - Unexpected token o"Babel/browserify 抛出“解析 JSON 时出错 - 意外的令牌 o”
【发布时间】:2016-12-18 18:53:31
【问题描述】:

尝试使用 browserify 和 babel 时出现奇怪的错误:

./node_modules/.bin/browserify app/index.js -o bundle.js -t [ babelify --presets [ es2015 react ] ]

给予:

SyntaxError: /.../package.json: Error while parsing JSON - Unexpected token o in JSON at position 1 while parsing file: /.../index.js
    at Object.parse (native)
    at ConfigChainBuilder.addConfig (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:155:65)
    at ConfigChainBuilder.findConfigs (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:107:30)
    at buildConfigChain (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:66:13)
    at OptionManager.init (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/option-manager.js:369:58)
    at File.initOptions (/.../dash/node_modules/babelify/node_modules/babel-core/lib/transformation/file/index.js:223:65)
    at new File

我为 es2015 安装了正确的预设并做出了反应,但我不知道为什么它会抛出这个错误。奇怪的是,这个命令在我的生产服务器上运行......

有什么想法吗?

【问题讨论】:

  • Browserify 检查 package.json 文件,这就是错误的来源,因此它与 Babel 和预设无关。如果您的package.json 与生产服务器上的相同(该命令在该服务器上运行),我将完全重新安装node_modules 等。
  • 我在父目录中有一个杂散的 package.json 文件。谢谢!

标签: reactjs browserify babeljs babel-core


【解决方案1】:

这是package.json解析错误,检查我的用户目录下是否有package.json文件,如果存在则删除。

【讨论】:

    猜你喜欢
    • 2013-03-15
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    相关资源
    最近更新 更多