【问题标题】:RXjs issues when deployed on Heroku在 Heroku 上部署时的 RXjs 问题
【发布时间】:2017-01-11 11:52:09
【问题描述】:

我有一个基于 nodeJS / Angular2 的站点,它在我的本地 Windows 10 机器上运行良好。但是,当我尝试部署到 Heroku 并访问该站点时,前端控制台 (Chrome) 会引发以下错误并且该站点无法加载。

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

【问题讨论】:

  • Rx.js 是否存在于您的部署 node_modules/rxjs/RX.js 位置?否则在您的systemjs.config.js 文件中相应地更改位置路径。
  • @Sanket 不,如果我在本地运行项目,http://localhost:3000/node_modules/rxjs/RX.js 会显示 js 源,但是,完全相同的项目在 Heroku 上返回 404?
  • 完全相同的项目是什么意思...您是否在 Heroku 上部署了整个 node_modules 文件夹并且仍然出现此错误?
  • @Sanket 所以我有一个带有package.json 的回购协议,它安装了一个 node_modules 目录。如果我运行git push heroku master 并观看this 输出,那么会安装一些(?)依赖项,结果会引发此问题。相同的仓库在本地工作
  • 检查日志中的第 84 行和第 111 行,上面写着 - UNMET PEER DEPENDENCY rxjs@5.0.0-beta.11

标签: javascript node.js heroku angular


【解决方案1】:

在您的包中,您没有指定 rxjs 的主脚本。 这就是我在 AngularRC.6 中所做的:

'rxjs': {main:'Rx'}

【讨论】:

  • 恐怕'rxjs': { main: 'Rx', defaultExtension: 'js' }, 还是会出现同样的错误...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-16
  • 2021-08-01
  • 2021-12-31
  • 1970-01-01
  • 2015-06-05
  • 1970-01-01
相关资源
最近更新 更多