vue 打包报错 npm run build

简介: npm run buildvue 打包报错WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

npm run build
vue 打包报错

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.output.filename: A relative path is expected. However the provided value "/static/js/[name].[chunkhash].js" is an absolute path!
   -> Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
   Please use output.path to specify absolute path and output.filename for the file name.
    at webpack (/Users/apple/Desktop/demo/dr-admin/node_modules/webpack/lib/webpack.js:19:9)
    at err (/Users/apple/Desktop/demo/dr-admin/build/build.js:19:3)
    at next (/Users/apple/Desktop/demo/dr-admin/node_modules/rimraf/rimraf.js:75:7)
    at CB (/Users/apple/Desktop/demo/dr-admin/node_modules/rimraf/rimraf.js:111:9)
    at /Users/apple/Desktop/demo/dr-admin/node_modules/rimraf/rimraf.js:137:14
    at FSReqWrap.oncomplete (fs.js:153:21)

-configuration.output.filename:应为相对路径。但是提供的值“/static/js/[name].[chunkhash].js”是绝对路径!

找到 config/index.js 里面的 assetsSubDirectory: '/static'是否绝对路径,除了 index.html 之外的静态资源要存放的路径,这里改为相对路径

  build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/sub/',

    /**
     * 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: true,
    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
  }
目录
相关文章
|
18天前
|
前端开发 JavaScript API
极简运行Vue打包文件:让你的网页快速启动,高效展现!
欢迎来到前端入门之旅!这个专栏是为那些对Web开发感兴趣、刚刚开始学习前端的读者们打造的。无论你是初学者还是有一些基础的开发者,我们都会在这里为你提供一个系统而又亲切的学习平台。我们以问答形式更新,为大家呈现精选的前端知识点和最佳实践。通过深入浅出的解释概念,并提供实际案例和练习,让你逐步建立起一个扎实的基础。无论是HTML、CSS、JavaScript还是最新的前端框架和工具,我们都将为你提供丰富的内容和实用技巧,帮助你更好地理解并运用前端开发中的各种技术。
|
20天前
|
JavaScript 前端开发
总结 Vue3 的一些知识点:Vue3 项目打包
总结 Vue3 的一些知识点:Vue3 项目打包
|
24天前
|
JavaScript
vue ssr 报错 ReferenceError: MouseEvent is not defined / window is not defined 等等
vue ssr 报错 ReferenceError: MouseEvent is not defined / window is not defined 等等
18 0
|
27天前
|
JavaScript
无法安装Vue脚手架 npm install @vue/cli -g
无法安装Vue脚手架 npm install @vue/cli -g
|
1月前
|
前端开发 JavaScript 小程序
亚马逊云科技 Build On -Serverless低代码平台初体验-快速完成vue前端订单小程序
亚马逊云科技 Build On -Serverless低代码平台初体验-快速完成vue前端订单小程序
24 0
|
1月前
|
JavaScript 数据安全/隐私保护 开发者
解决vue引发的报错-sub is not a function at vuex.esm.js:422:1跳转不了路由的问题
解决vue引发的报错-sub is not a function at vuex.esm.js:422:1跳转不了路由的问题
16 0
|
1月前
|
JavaScript 前端开发
Vue报错“ Uncaught TypeError: Cannot read property ‘use‘ of undefined”
Vue报错“ Uncaught TypeError: Cannot read property ‘use‘ of undefined”
25 1
|
1月前
vue3-admin-element-template配置正向代理报错
vue3-admin-element-template配置正向代理报错
23 0
|
1月前
|
JavaScript
Vue项目如何打包
Vue项目如何打包
11 0
|
1月前
|
JavaScript
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
30 0

相关产品

  • 云迁移中心
  • 推荐镜像

    更多