【问题标题】:Static assets not serving on Heroku but do locally?静态资产不在 Heroku 上提供但在本地提供?
【发布时间】:2017-01-14 01:14:11
【问题描述】:

我有一个基于 nodeJS + expressJS + Angular2-RC.5 的站点,它在我的本地 Windows 10 机器上运行良好。但是,当我尝试将(here's 日志)部署到 Heroku 并访问该站点时,前端控制台 (Chrome) 会引发以下错误并且该站点无法加载。 Heroku 上没有提供 RXjs 似乎有一些问题?

zone.js:101 GET https://ns-docs.herokuapp.com/node_modules/rxjs/RX.js 404(未找到)

我的systemjs.config.js 包含以下内容:

(function(global) {
  // map tells the System loader where to look for things
  var map = {
    'app':                        '/app', // 'dist',
    '@angular':                   '/node_modules/@angular',
    'angular2-in-memory-web-api': '/node_modules/angular2-in-memory-web-api',
    'rxjs':                       '/node_modules/rxjs'
  };
  // packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'app':                        { main: 'main.js',  defaultExtension: 'js' },
    'rxjs':                       { defaultExtension: 'js' },
    'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
  };

  System.config(config);
})(this);

我的index.html 包含:

...
    <script src="/node_modules/core-js/client/shim.min.js"></script>
    <script src="/node_modules/zone.js/dist/zone.js"></script>
    <script src="/node_modules/reflect-metadata/Reflect.js"></script>
    <script src="/node_modules/systemjs/dist/system.src.js"></script>
    <!-- 2. Configure SystemJS -->
    <script src="/config/systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
    <base href="/">
</head>

所以如果我在本地运行项目,http://localhost:3000/node_modules/rxjs/RX.js 会显示 js 源。 但是,如果我使用 this 构建日志将项目推送到 Heroku,则该版本在 /node_modules/rxjs/RX.js 上返回 404

更新:

如果我将我的 repo 克隆到我机器上的新位置,cd 到项目根目录,运行 npm i ,然后运行 ​​git submodule update --init" thennode ./bin/www` 然后项目在 localhost 上运行良好。我认为这意味着 repo 中的所有信息都足以使项目正常运行。所以我仍然怀疑这与我的静态驴在 Heroku 和我的本地机器上的服务方式有关。

【问题讨论】:

    标签: node.js express heroku angular rxjs


    【解决方案1】:

    服务器可能是基于 linux 的,并且文件/文件夹名称区分大小写。这是Rx.js 不是RX.js。所以你在某处搞错了import

    【讨论】:

    • 我不会在应用程序的任何地方导入rxjs,它只是作为angular的子依赖
    • 哦.. 那么.. 会发生一些事情 :D,因为尝试转到 /node_modules/rxjs/Rx.js 并且它会起作用
    • 好的,你是对的!我会尽力追查...有什么想法吗?
    • 不知道为什么会这样,因为我的config.system.js中明确指定了正确的大小写?
    • 在您的项目(尤其是 node_modules 文件夹)中搜索 RX :) 确保区分大小写
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 2011-09-21
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 2018-10-10
    相关资源
    最近更新 更多