无法运行npm run build生成前端静态文件
Closed this issue · 1 comments
CHN-STUDENT commented
C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin>npm run build --report
> web-flash-vue-admin@1.0.0 build C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin
> node build/build.js
- building for undefined...C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\script-ext-html-webpack-plugin\lib\plugin.js:50
compilation.hooks.htmlWebpackPluginAlterAssetTags.tap(PLUGIN, alterAssetTags);
^
TypeError: Cannot read property 'tap' of undefined
at ScriptExtHtmlWebpackPlugin.compilationCallback (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\script-ext-html-webpack-plugin\lib\plugin.js:50:57)
at SyncHook.eval [as call] (eval at create (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:11:1)
at SyncHook.lazyCompileHook (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\tapable\lib\Hook.js:154:20)
at Compiler.newCompilation (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\webpack\lib\Compiler.js:504:26)
at hooks.beforeCompile.callAsync.err (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\webpack\lib\Compiler.js:540:29)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\tapable\lib\Hook.js:154:20)
at Compiler.compile (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\webpack\lib\Compiler.js:535:28)
at readRecords.err (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\webpack\lib\Compiler.js:274:11)
at Compiler.readRecords (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\webpack\lib\Compiler.js:402:11)
at hooks.run.callAsync.err (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\webpack\lib\Compiler.js:271:10)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\tapable\lib\Hook.js:154:20)
at hooks.beforeRun.callAsync.err (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\webpack\lib\Compiler.js:268:19)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\tapable\lib\Hook.js:154:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! web-flash-vue-admin@1.0.0 build: `node build/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the web-flash-vue-admin@1.0.0 build 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\Mr.Guo\AppData\Roaming\npm-cache\_logs\2019-08-13T10_48_14_380Z-debug.log
日志文件
0 info it worked if it ends with ok
1 verbose cli [ 'D:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build',
1 verbose cli '--report' ]
2 info using npm@6.9.0
3 info using node@v10.16.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle web-flash-vue-admin@1.0.0~prebuild: web-flash-vue-admin@1.0.0
6 info lifecycle web-flash-vue-admin@1.0.0~build: web-flash-vue-admin@1.0.0
7 verbose lifecycle web-flash-vue-admin@1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle web-flash-vue-admin@1.0.0~build: PATH: D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\jdk8\bin;D:\msys2\home\Mr.Guo\openssl-1.0.2q\dist\bin;D:\msys64\mingw32\bin;C:\Program Files\CMake\bin;C:\Program Files\Git\cmd;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;D:\TDM\bin;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;D:\matlab\runtime\win64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;D:\matlab\bin;D:\matlab\polyspace\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;D:\swipl\bin;D:\apache-maven-3.6.1\bin;D:\Program Files\nodejs\;C:\Program Files\dotnet\;D:\redis\;C:\ProgramData\Oracle\Java\javapath;D:\anaconda;D:\anaconda\Library\mingw-w64\bin;D:\anaconda\Library\usr\bin;D:\anaconda\Library\bin;D:\anaconda\Scripts;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;D:\IntelliJ IDEA 2019.1.2\bin;D:\VS Code\bin;C:\Users\Mr.Guo\AppData\Local\GitHubDesktop\bin;D:\Fiddler;C:\Users\Mr.Guo\AppData\Roaming\npm;D:\WebStorm 2019.2\bin;
9 verbose lifecycle web-flash-vue-admin@1.0.0~build: CWD: C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin
10 silly lifecycle web-flash-vue-admin@1.0.0~build: Args: [ '/d /s /c', 'node build/build.js' ]
11 silly lifecycle web-flash-vue-admin@1.0.0~build: Returned: code: 1 signal: null
12 info lifecycle web-flash-vue-admin@1.0.0~build: Failed to exec build script
13 verbose stack Error: web-flash-vue-admin@1.0.0 build: `node build/build.js`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid web-flash-vue-admin@1.0.0
15 verbose cwd C:\Users\Mr.Guo\Documents\GitHub\web-flash-master\flash-vue-admin
16 verbose Windows_NT 10.0.17763
17 verbose argv "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build" "--report"
18 verbose node v10.16.0
19 verbose npm v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error web-flash-vue-admin@1.0.0 build: `node build/build.js`
22 error Exit status 1
23 error Failed at the web-flash-vue-admin@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 ]
您是否有建议修复此问题,谢谢!
CHN-STUDENT commented
关于css,html找不到问题,修改index.js
,参考如下
'use strict'
const path = require('path')
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://127.0.0.1:8082', //设置调用接口地址和端口号别忘了加http
changeOrigin: true,
pathRewrite: {
'^/api': '/' //这里理解成用‘/api’代替target里面的地址,组件中我们调接口时直接用/api代替
// 比如我要调用'http://0.0:300/user/add',直接写‘/api/user/add’即可 代理后地址栏显示/
}
}
},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 9528, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: true,
errorOverlay: true,
notifyOnErrors: false,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
// Use Eslint Loader?
// If true, your code will be linted during bundling and
// linting errors and warnings will be shown in the console.
useEslint: true,
// If true, eslint errors and warnings will also be shown in the error overlay
// in the browser.
showEslintErrorsInOverlay: false,
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'cheap-source-map',
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
},
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
/**
* You can set by youself according to actual condition
* You will need to set this if you plan to deploy your site under a sub path,
* for example GitHub pages. If you plan to deploy your site to https://foo.github.io/bar/,
* then assetsPublicPath should be set to "/bar/".
* In most cases please use '/' !!!
*/
assetsPublicPath: '/', // If you are deployed on the root path, please use '/'
/**
* Source Maps
*/
productionSourceMap: false,
// https://webpack.js.org/configuration/devtool/#production
devtool: 'source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report || false,
// `npm run build:prod --generate_report`
generateAnalyzerReport: process.env.npm_config_generate_report || false
}
}
使用nginx作为HTTP服务器,参考配置文件如下
server {
listen 8081;
server_name localhost;
root /www/wwwroot/dist;
index index.html;
#access_log /var/log/testwx.log main;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
}