安置裝vue-cli之後npm run dev正常顯示localhost, 熱更新也沒問題, 但現在要發布時 npm run build 卻報錯, 昨天網上有人說重裝也重新安裝webpack了, 也update npm了, node_modules也重裝了, 還是報錯
SyntaxError: Invalid or unexpected token
但卻找不到是哪裡的語法錯誤
希望各位大神解救
debug.log
0 info it worked if it ends with ok1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',1 verbose cli 'C:\\Users\\bbs\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',1 verbose cli 'run',1 verbose cli 'build' ]2 info using npm@5.3.03 info using node@v7.9.04 verbose run-script [ 'prebuild', 'build', 'postbuild' ]5 info lifecycle y@1.0.0~prebuild: y@1.0.06 info lifecycle y@1.0.0~build: y@1.0.07 verbose lifecycle y@1.0.0~build: unsafe-perm in lifecycle true8 verbose lifecycle y@1.0.0~build: PATH: C:\Users\bbs\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;D:\schientify\node_modules\.bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Java\jdk1.8.0_77\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;D:\brackets\command;C:\Users\bbs\Anaconda3;C:\Users\bbs\Anaconda3\Scripts;C:\Users\bbs\Anaconda3\Library\bin;C:\Users\bbs\AppData\Local\Microsoft\WindowsApps;C:\Users\bbs\AppData\Roaming\npm9 verbose lifecycle y@1.0.0~build: CWD: D:\schientify10 silly lifecycle y@1.0.0~build: Args: [ '/d /s /c',10 silly lifecycle 'webpack-dev-server --devtool eval --hot --content-base build' ]11 silly lifecycle y@1.0.0~build: Returned: code: 1 signal: null12 info lifecycle y@1.0.0~build: Failed to exec build script13 verbose stack Error: y@1.0.0 build: `webpack-dev-server --devtool eval --hot --content-base build`13 verbose stack Exit status 113 verbose stack at EventEmitter.<anonymous> (C:\Users\bbs\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:289:16)13 verbose stack at emitTwo (events.js:106:13)13 verbose stack at EventEmitter.emit (events.js:194:7)13 verbose stack at ChildProcess.<anonymous> (C:\Users\bbs\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:40:14)13 verbose stack at emitTwo (events.js:106:13)13 verbose stack at ChildProcess.emit (events.js:194:7)13 verbose stack at maybeClose (internal/child_process.js:899:16)13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)14 verbose pkgid y@1.0.015 verbose cwd D:\schientify16 verbose Windows_NT 10.0.1439317 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\bbs\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"18 verbose node v7.9.019 verbose npm v5.3.020 error code ELIFECYCLE21 error errno 122 error y@1.0.0 build: `webpack-dev-server --devtool eval --hot --content-base build`22 error Exit status 123 error Failed at the y@1.0.0 build script.23 error This is probably not a problem with npm. There is likely additional logging output above.24 verbose exit [ 1, true ]
package.json
{ "name": "y", "version": "1.0.0", "description": "y", "author": "y", "private": true, "scripts": { "dev": "node build/dev-server.js", "start": "node build/dev-server.js", "build": "webpack-dev-server --devtool eval --hot --content-base build", "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", "e2e": "node test/e2e/runner.js", "test": "npm run unit && npm run e2e" }, "dependencies": { "compass": "^0.1.1", "compass-mixins": "^0.12.10", "vue": "^2.4.2", "vue-router": "^2.6.0", "vuex": "^2.3.1" }, "devDependencies": { "autoprefixer": "^7.1.2", "babel-core": "^6.22.1", "babel-loader": "^7.1.1", "babel-plugin-istanbul": "^4.1.1", "babel-plugin-transform-runtime": "^6.22.0", "babel-preset-env": "^1.3.2", "babel-preset-stage-2": "^6.22.0", "babel-register": "^6.22.0", "chai": "^3.5.0", "chalk": "^2.0.1", "chromedriver": "^2.27.2", "connect-history-api-fallback": "^1.3.0", "copy-webpack-plugin": "^4.0.1", "cross-env": "^5.0.2", "cross-spawn": "^5.0.1", "css-loader": "^0.28.0", "cssnano": "^3.10.0", "eventsource-polyfill": "^0.9.6", "express": "^4.14.1", "extract-text-webpack-plugin": "^2.0.0", "file-loader": "^0.11.1", "friendly-errors-webpack-plugin": "^1.1.3", "html-webpack-plugin": "^2.30.1", "http-proxy-middleware": "^0.17.3", "inject-loader": "^3.0.1", "karma": "^1.4.1", "karma-coverage": "^1.1.1", "karma-mocha": "^1.3.0", "karma-phantomjs-launcher": "^1.0.2", "karma-phantomjs-shim": "^1.4.0", "karma-sinon-chai": "^1.3.1", "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.31", "karma-webpack": "^2.0.2", "lolex": "^1.5.2", "mocha": "^3.5.0", "nightwatch": "^0.9.12", "node-sass": "^4.5.3", "opn": "^5.1.0", "optimize-css-assets-webpack-plugin": "^2.0.0", "ora": "^1.2.0", "phantomjs-prebuilt": "^2.1.14", "rimraf": "^2.6.0", "sass-loader": "^6.0.6", "selenium-server": "^3.0.1", "semver": "^5.3.0", "shelljs": "^0.7.6", "sinon": "^2.1.0", "sinon-chai": "^2.8.0", "url-loader": "^0.5.8", "vue-loader": "^12.1.0", "vue-style-loader": "^3.0.1", "vue-template-compiler": "^2.4.2", "webpack": "^2.7.0", "webpack-bundle-analyzer": "^2.2.1", "webpack-dev-middleware": "^1.12.0", "webpack-hot-middleware": "^2.18.0", "webpack-merge": "^4.1.0" }, "engines": { "node": ">= 4.0.0", "npm": ">= 3.0.0" }, "browserslist": [ "> 1%", "last 2 versions", "not ie <= 8" ]}
webpack.config.js
var path = require('path')var webpack = require('webpack')module.exports = { entry: './src/main.js', output: { path: path.resolve(__dirname, './dist'), publicPath: '/dist/', filename: 'build.js' }, module: { rules: [{ test: /\.vue$/, loader: 'vue-loader', options: { loaders: { // Since sass-loader (weirdly) has SCSS as its default parse mode, we mapnpm run de // the "scss" and "sass" values for the lang attribute to the right configs here. // other preprocessors should work out of the box, no loader config like this necessary. 'scss': 'vue-style-loader!css-loader!sass-loader', 'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax' } // other vue-loader options go here } }, { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }, { test: /\.(png|jpg|gif|svg)$/, loader: 'file-loader', options: { name: '[name].[ext]?[hash]' } } ] }, resolve: { alias: { 'vue$': 'vue/dist/vue.esm.js' } }, devServer: { historyApiFallback: true, noInfo: true }, performance: { hints: false }, devtool: '#eval-source-map'}if (process.env.NODE_ENV === 'production') { module.exports.devtool = '#source-map' // http://vue-loader.vuejs.org/en/workflow/production.html module.exports.plugins = (module.exports.plugins || []).concat([ new webpack.DefinePlugin({ 'process.env': { NODE_ENV: '"production"' } }), new webpack.optimize.UglifyJsPlugin({ sourceMap: true, compress: { warnings: false } }), new webpack.LoaderOptionsPlugin({ minimize: true }) ])}
解决方案
觉得你需要这个 http://www.ruanyifeng.com/blog/2016/10/npm_scripts.html