gpt4 book ai didi

node.js - 静态资源不在 Heroku 上运行,但在本地运行?

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:22 24 4
gpt4 key购买 nike

我有一个基于 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 (Not Found)

enter image description here

我的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 源。但是,如果我将项目推送到 Heroku,使用 this构建日志,该版本在 /node_modules/rxjs/RX.js

上返回 404

更新:

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

最佳答案

服务器可能是基于 Linux 的,文件/文件夹名称区分大小写。它是 Rx.js 而不是 RX.js。所以你在某处导入有错误

关于node.js - 静态资源不在 Heroku 上运行,但在本地运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39351381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com