有人可以帮助我解决这个问题:我试图在laravel项目中执行npm运行生产(也使用webpack),并在位置132处获取SyntaxError:Unexpected token / in JSON(以及如何使用vscode捕获它们)尝试转换为JSON似乎有些错误,但我找不到它。谢谢您的帮助 这是github repo
cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\bin\cli.js:93
throw err;
^
SyntaxError: Unexpected token / in JSON at position 132
at JSON.parse (<anonymous>)
at BabelConfig.fetchBabelRc (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\BabelConfig.js:30:41)
at Function.generate (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\BabelConfig.js:14:35)
at Object.babel (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\config.js:121:45)
at JavaScript.webpackRules (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\components\JavaScript.js:76:41)
at ComponentFactory.applyRules (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\components\ComponentFactory.js:155:23)
at Mix.listen.rules (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\components\ComponentFactory.js:66:48)
at events.(anonymous function).forEach.handler (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\Dispatcher.js:34:47)
at Array.forEach (<anonymous>)
at Dispatcher.fire (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\Dispatcher.js:34:28)
at Mix.dispatch (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\Mix.js:119:25)
at WebpackConfig.buildRules (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\builder\WebpackConfig.js:83:13)
at WebpackConfig.build (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\src\builder\WebpackConfig.js:23:14)
at Object.<anonymous> (F:\Projects\js\vue\vue-appEp19\node_modules\laravel-mix\setup\webpack.config.js:29:38)
at Module._compile (F:\Projects\js\vue\vue-appEp19\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (F:\Projects\js\vue\vue-appEp19\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
at WEBPACK_OPTIONS (F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\bin\utils\convert-argv.js:116:13)
at requireConfig (F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\bin\utils\convert-argv.js:118:6)
at F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\bin\utils\convert-argv.js:125:17
at Array.forEach (<anonymous>)
at module.exports (F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\bin\utils\convert-argv.js:123:15)
at yargs.parse (F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\bin\cli.js:71:45)
at Object.parse (F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\node_modules\yargs\yargs.js:567:18)
at F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\bin\cli.js:49:8
at Object.<anonymous> (F:\Projects\js\vue\vue-appEp19\node_modules\webpack-cli\bin\cli.js:365:3)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ 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`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Vlad\AppData\Roaming\npm-cache\_logs\2019-07-07T07_05_11_119Z-debug.log
答案 0 :(得分:0)
当WebPack尝试解析babel配置时,似乎出现了问题。从您提供的存储库URL中查看您的.babelrc,我发现
{
"presets": [
"@babel/preset-env",
"@babel/env",
["es2015", {"modules":false}]
]
}
// {
// "presets": [
// "@babel/preset-env",
// "@babel/preset-react",
// ["es2015", {"modules":false}]
// ],
// "plugins": [
// "transform-class-properties",
// "transform-object-rest-spread"
// ]
// }
Babel配置是一个JSON文件。该文件应仅包含有效的JSON对象。似乎您不知道JSON不支持注释。因此,您应该删除所有以“ //”开头的行。希望你的问题会消失。
如果您想了解有关JSON中注释的更多信息,请参见here的第二个答案