vue项目打包上线时报错‘Failed to load resource: net::ERR_FILE_NOT_FOUND‘

发布时间 2023-07-03 14:35:17作者: 海乐学习

vue项目打包上线时报错’Failed to load resource: net::ERR_FILE_NOT_FOUND’

原因:
这里的确是css以及js文件的路径问题

解决方案:

解决时并不需要手动改路径或者加一段判断去修改 

最方便的办法时在项目打包前的 vue.config.js 里面将publicPath属性  添加或者修改为 publicPath: ‘./’, 然后重新打包。

修改为:

vue.config.js

const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({

  transpileDependencies: true,

  publicPath: './'

})

如图