我的MEAN应用程序的文件结构如下:
root
|---> public
|----> css
|----> js
|----> controller
|----> app.js
|----> views
|----> index.html
|---> app
|----> server.js
|---> node_modules
|---> bower_components
|---> gulpfile.js
|---> package.json
|---> Procfile
Run Code Online (Sandbox Code Playgroud)
在这个应用程序中,我运行public/index.html使用gulp,
gulpfile.js:
var gulp = require('gulp');
var browserSync = require('browser-sync');
var server = require('gulp-live-server');
gulp.task('server', function() {
live = new server('app/server.js');
live.start();
})
gulp.task('serve', ['server'], function() {
browserSync.init({
notify: false,
port: process.env.PORT || 8080,
server: {
baseDir: ['public'],
routes: {
'/bower_components': 'bower_components'
}
}
});
gulp.watch(['public/**/*.*'])
.on('change', browserSync.reload);
});
Run Code Online (Sandbox Code Playgroud)
然后与app使用沟通REST API.这是在本地机器上工作.我已将此项目上传到heroku.
我的Procfile:
web: node node_modules/gulp/bin/gulp serve
Run Code Online (Sandbox Code Playgroud)
但它显示错误.我有以下错误heroku logs
2017-05-21T16:26:57.305350+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myapp.herokuapp.com request_id=some-request-id fwd="fwd-ip" dyno= connect= service= status=503 bytes= protocol=https
2017-05-21T15:53:50.942664+00:00 app[web.1]: Error: Cannot find module '/app/node_modules/gulp/bin/gulp'
我的package.json档案:
{
"name": "myapp",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "gulp serve"
},
"repository": {
"type": "git",
"url": ""
},
"dependencies": {
"async": "^2.4.0",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"mongoose": "^4.10.0",
"morgan": "^1.8.1",
"multer": "^1.3.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"browser-sync": "^2.18.11",
"gulp": "^3.9.1",
"gulp-live-server": "0.0.30"
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?提前致谢.
您可能已在文件中gulp定义为开发依赖项(在 下devDepenenies)package.json。NPM 仅在未设置为devDependencies时安装。NODE_ENVproduction
当您部署到 heroku 时,永远不会安装 , NODE_ENV=productionso 。gulp因此错误...
Error: Cannot find module '/app/node_modules/gulp/bin/gulp'
只需移动以及从到gulp构建捆绑包所需的任何其他内容即可。你可以让 npm 为你移动它:devDependenciesdependencies
npm uninstall --save-dev gulp
npm install --save gulp
Run Code Online (Sandbox Code Playgroud)
对构建捆绑包所需的每个开发依赖项重复此操作。或者您可以自己复制并粘贴它们。
据我所知,这是一个没有理想解决方案的常见问题。NPM 期望在生产中,您已经预先构建了文件。就像您将它们发布到 NPM 一样。然而,在heroku和其他推送部署解决方案中,情况并非如此。
| 归档时间: |
|
| 查看次数: |
410 次 |
| 最近记录: |