0

我昨天在 vue/cli github 错误页面上发布了我的环境详细信息。看起来所有错误都没有得到响应,所以我希望你们能帮助我。

短版: 我有一个 Vue/Firebase 项目。我正在尝试构建它,以便可以在 Firebase 上部署它。当我通过 Vue UI 提供该项目时,该项目运行良好。当我运行npm run build时,创建的 /dist/index.html 文件的 href 都以“/undefined/...”开头。显然,当我将它部署到 Firebase 时,这不起作用,给我这样的错误Uncaught SyntaxError: Unexpected token '<'

可疑的事情:

  1. 部署到 Firebase 后,它仍然能够找到我的 favicon.ico,即使它认为它位于https://myproject.firebaseapp.com/undefined/favicon.ico.
  2. 在我的环境信息中,我有npmGlobalPackages: @vue/cli: Not Found. 我尝试的步骤在上述 GitHub 页面的评论中,但我无法更改。
  3. 在我的环境信息中,它说Browsers: Edge: 44.18362.449.0. 我不知道这是否重要,但我只是在 Chrome 中工作和测试。

我尝试过的事情

  1. 根据许多 stackoverflow 的答案,我可以Try by adding <base href="/" /> into the <head> of your index.html. Hope it will work., 和You might have used "./" prefix for Relative path in src attributes of your index.html, Just replace it with "<%= BASE_URL %>" and it will work fine.. 我都试过了,还是不行(我也试过提问者的npm install再次跑步的建议)。除了我所说的更改之外,我还有生成的 firebase index.html 文件。

  2. 根据许多其他问题,这Unexpected token '<'可能是 Firebase 的缓存问题。他们说我可以尝试硬刷新(我尝试过)或清除缓存(我也尝试过)。我什至尝试使用完全不同的计算机,但仍然遇到相同的错误。老实说,我不认为是这样,因为我不认为我的 dist/index.html 文件应该在其中未定义,这是在我将其上传到 Firebase 之前。

代码: vue.config.js

module.exports = {
  "transpileDependencies": [
    "vuetify"
  ],
  devServer: {
        proxy: 'https://myredactedprojectname.com/',
    },
  publicPath: process.env.NODE_ENV === 'production'
    ? '/' + process.env.CI_PROJECT_NAME + '/'
    : '/'
}

公共/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <base href="/" />
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>soa</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
  </head>
  <body>
    <noscript>
      <strong>We're sorry but soa doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

dist/index.html

<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><base href=/ ><link rel=icon href="/undefined/favicon.ico"><title>soa</title><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900"><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css><link href="/undefined/css/chunk-02393c0e.868814f6.css" rel=prefetch><link href="/undefined/css/chunk-0413c1cf.da33aaeb.css" rel=prefetch><link href="/undefined/css/chunk-05af17cb.0670aa22.css" rel=prefetch><link href="/undefined/css/chunk-05c2d357.0670aa22.css" rel=prefetch><link href="/undefined/css/chunk-05f9ac48.0670aa22.css" rel=prefetch><link href="/undefined/css/chunk-061bbc7c.0670aa22.css" rel=prefetch><link href="/undefined/css/chunk-0c3f6c05.fa43d5a7.css" rel=prefetch><link href="/undefined/css/chunk-0ffc1848.0cf83054.css" rel=prefetch><link href="/undefined/css/chunk-28537b2e.f613719f.css" rel=prefetch><link href="/undefined/css/chunk-2991328e.53d7c3bd.css" rel=prefetch><link href="/undefined/css/chunk-3451d3f0.0cf83054.css" rel=prefetch><link href="/undefined/css/chunk-50451b64.20012414.css" rel=prefetch><link href="/undefined/css/chunk-579e1ea3.36ca82f6.css" rel=prefetch><link href="/undefined/css/chunk-774d451a.bbdf16ed.css" rel=prefetch><link href="/undefined/css/chunk-796d4363.0cf83054.css" rel=prefetch><link href="/undefined/css/chunk-889ba836.0cf83054.css" rel=prefetch><link href="/undefined/css/chunk-8b217ef2.0670aa22.css" rel=prefetch><link href="/undefined/css/chunk-a2794958.469377bf.css" rel=prefetch><link href="/undefined/css/chunk-a808dfec.0670aa22.css" rel=prefetch><link href="/undefined/css/chunk-a97ba050.343c0125.css" rel=prefetch><link href="/undefined/css/chunk-dbbcb6ca.afbf6e2a.css" rel=prefetch><link href="/undefined/js/chunk-02393c0e.1131b09f.js" rel=prefetch><link href="/undefined/js/chunk-0413c1cf.226cb5af.js" rel=prefetch><link href="/undefined/js/chunk-05af17cb.03fb4e75.js" rel=prefetch><link href="/undefined/js/chunk-05c2d357.d226fc27.js" rel=prefetch><link href="/undefined/js/chunk-05f9ac48.bf6105aa.js" rel=prefetch><link href="/undefined/js/chunk-061bbc7c.616f91e0.js" rel=prefetch><link href="/undefined/js/chunk-0c3f6c05.cd0b340b.js" rel=prefetch><link href="/undefined/js/chunk-0ffc1848.fc935ef9.js" rel=prefetch><link href="/undefined/js/chunk-28537b2e.46a32516.js" rel=prefetch><link href="/undefined/js/chunk-2991328e.007c3af2.js" rel=prefetch><link href="/undefined/js/chunk-2d22922a.59463fdb.js" rel=prefetch><link href="/undefined/js/chunk-2d22a109.07601e72.js" rel=prefetch><link href="/undefined/js/chunk-2d22d746.c132ede6.js" rel=prefetch><link href="/undefined/js/chunk-3451d3f0.88a2ff05.js" rel=prefetch><link href="/undefined/js/chunk-3f6524ae.aaee21ad.js" rel=prefetch><link href="/undefined/js/chunk-50451b64.8e065900.js" rel=prefetch><link href="/undefined/js/chunk-579e1ea3.6d02e597.js" rel=prefetch><link href="/undefined/js/chunk-774d451a.ed3b640a.js" rel=prefetch><link href="/undefined/js/chunk-796d4363.0c75e4bf.js" rel=prefetch><link href="/undefined/js/chunk-889ba836.e0cd6e81.js" rel=prefetch><link href="/undefined/js/chunk-8b217ef2.ced2c34f.js" rel=prefetch><link href="/undefined/js/chunk-a0d25322.4e3c26f4.js" rel=prefetch><link href="/undefined/js/chunk-a2794958.e198bb98.js" rel=prefetch><link href="/undefined/js/chunk-a808dfec.07a35948.js" rel=prefetch><link href="/undefined/js/chunk-a97ba050.51a395a6.js" rel=prefetch><link href="/undefined/js/chunk-dbbcb6ca.c0c8846c.js" rel=prefetch><link href="/undefined/css/chunk-vendors.434320c7.css" rel=preload as=style><link href="/undefined/js/app.0215a074.js" rel=preload as=script><link href="/undefined/js/chunk-vendors.6698b677.js" rel=preload as=script><link href="/undefined/css/chunk-vendors.434320c7.css" rel=stylesheet></head><body><noscript><strong>We're sorry but soa doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src="/undefined/js/chunk-vendors.6698b677.js"></script><script src="/undefined/js/app.0215a074.js"></script></body></html>
4

1 回答 1

1

所以,事实证明我的环境变量没有设置,这就是它出现未定义的原因。我只是将我的公共路径设置为“/”。

vue.config.js:

module.exports = {
  "transpileDependencies": [
    "vuetify"
  ],
  devServer: {
        proxy: 'https://myprojectname.com/',
    },
  publicPath: '/'
}
于 2020-03-18T04:19:44.257 回答