【发布时间】: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