代码的本地版本有效,但在推送到 heroku 时中断 - multer gcs
Local version of code works, but breaks when pushing to heroku - multer gcs
我有一个表单,我可以在其中提交图片并将它们上传到 Firebase。我在本地构建了这个项目,但是当我将它推送到 Heroku 时它就崩溃了。
快递:
var gcs = require( 'multer-gcs' );
var storage = gcs({
filename : function( req, file, cb ) {
cb( null, file.fieldname + '-' + Date.now() );
},
bucket : 'mybucket.appspot.com', // Required : bucket name to upload
projectId : 'mybucket', // Required : Google project ID
keyFilename : './mybucket-firebase-adminsdk-4oyba-xee555bbgr.json', // Required : JSON credentials file for Google Cloud Storage
acl : 'publicread' // Optional : Defaults to private
});
const multer = require('multer');
var upload = multer({storage: storage});
app.post('/sell', upload.any(), homeController.postSellPage);
第一个错误代码(来自 Heroku Logs
):
Error: Cannot find module 'multer-gcs'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at Object.<anonymous> (/app/app.js:22:11)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at tryModuleLoad (module.js:446:12)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
然后我 运行 以下内容以更新我的 package.json
:npm install multer-gcs --save
,并安装了它,同时给我这条消息:
deprecated gcloud@0.36.0: gcloud has been renamed to google-cloud. To get new features and bug fixes, you must use the new package.
我不知道如何处理该消息,所以除了在提交新 package.json
后重新推送到 heroku 之外,我什么也没做。我遇到以下问题:
Build failed
Outdated Yarn lockfile
Your application contains a Yarn lockfile (yarn.lock) which does not
match the dependencies in package.json. This can happen if you use npm
to install or update a dependency instead of Yarn.
Please run the following command in your application directory and check
in the new yarn.lock file:
$ yarn install
$ git add yarn.lock
$ git commit -m "Updated Yarn lockfile"
$ git push heroku master
https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-an-outdated-yarn-lockfile
然后我 运行 yarn install
,但得到了
The engine "node" is incompatible with this module. Expected version "6.9.5".
Found incompatible module
Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
所以我查看并在 package.json 中有以下内容,其中包括节点 6.9.5
,所以我认为我在这方面没问题。
"engines": {
"node": "6.9.5",
"npm": "4.6.1",
"yarn": "1.3.2"
},
然后我 运行 yarn install --ignore-engines
,基于关于同一问题的 posting。这给了我以下内容:
/Users/user/path/node_modules/gcloud/node_modules/grpc: Command failed.
Exit code: 127
Command: ./node_modules/.bin/node-pre-gyp install --fallback-to-build
我尝试了 运行 这个命令 npm install --unsafe-perm
,基于另一个 posting,但是 grpc
又出现了这个问题。
我希望得到任何关于如何让 heroku 进入 accept/run 构建的帮助,因为我在这个问题上遇到了困难。如果需要任何说明,请告诉我。
根据要求,package.json
:
{
"name": "App Name",
"version": "0.0.2",
"description": "Amazing Application",
"engines": {
"node": "6.9.5",
"npm": "4.6.1",
"yarn": "1.3.2"
},
"repository": {
"type": "git",
"url": "https://github.com/amazing_app.git"
},
"author": "Example",
"license": "Example",
"scripts": {
"start": "node app.js",
"test": "mocha --reporter spec",
"postinstall": "npm rebuild node-sass"
},
"dependencies": {
"aws-sdk": "^2.46.0",
"bcrypt-nodejs": "^0.0.3",
"bluebird": "^3.4.7",
"body-parser": "^1.15.2",
"chalk": "^1.1.3",
"cheerio": "^0.22.0",
"clockwork": "^0.1.4",
"compression": "^1.6.2",
"connect-mongo": "^1.3.2",
"dotenv": "^4.0.0",
"errorhandler": "^1.4.3",
"express": "^4.14.0",
"express-flash": "^0.0.2",
"express-session": "^1.14.2",
"express-status-monitor": "^0.1.5",
"express-validator": "^3.1.2",
"fbgraph": "^1.3.0",
"firebase": "^3.9.0",
"firebase-admin": "^4.2.1",
"github": "^9.2.0",
"grpc": "1.3.8",
"instagram-node": "^0.5.8",
"lastfm": "^0.9.2",
"lob": "^3.9.0",
"lusca": "^1.4.1",
"mongoose": "^4.6.6",
"morgan": "^1.7.0",
"multer": "^1.3.0",
"multer-gcs": "^1.0.2",
"node-base64-image": "^1.0.3",
"node-foursquare": "^0.3.0",
"node-linkedin": "^0.5.4",
"node-sass-middleware": "^0.11.0",
"nodemailer": "^3.1.7",
"passport": "0.3.2",
"passport-facebook": "^2.1.1",
"passport-github": "^1.1.0",
"passport-google-oauth": "^1.0.0",
"passport-instagram": "^1.0.0",
"passport-linkedin-oauth2": "^1.4.1",
"passport-local": "^1.0.0",
"passport-oauth": "^1.0.0",
"passport-openid": "^0.4.0",
"passport-twitter": "^1.0.4",
"paypal-rest-sdk": "^1.7.0",
"pug": "^2.0.0-beta6",
"request": "^2.78.0",
"stripe": "^4.12.0",
"tumblr.js": "^1.1.1",
"twilio": "^3.3.1-edge",
"twit": "^2.2.5",
"validator": "^7.0.0"
},
"devDependencies": {
"chai": "^3.5.0",
"eslint": "^3.9.1",
"eslint-config-airbnb-base": "^11.0.0",
"eslint-plugin-import": "^2.1.0",
"mocha": "^3.1.2",
"supertest": "^3.0.0"
},
"eslintConfig": {
"extends": "airbnb-base",
"rules": {
"comma-dangle": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"no-shadow": 0,
"no-console": 0,
"no-plusplus": 0
}
}
}
**注意:**只有当我取消注释 Express
下的内容(如上所示)时才会中断。
更新:
当我将 AWS 与 Multer var multerS3 = require('multer-s3');var s3 = new aws.S3({});
一起使用时,应用程序将成功 post 到 Heroku var multerS3 = require('multer-s3');var s3 = new aws.S3({});
所以它必须与 GCS 及其依赖项有关
不是 100% 确定,但是您需要 包含 yarn.lock
文件吗?我知道它会将您的依赖项锁定在您使用的确切版本上,但在大多数情况下没有它应该没问题吗?
如果你git rm yarn.lock
理论上heroku可能更喜欢你。
也有可能是您的 node_modules 中的某些内容以某种方式损坏(我不是 100% 确定这是如何发生的)或者您的 yarn.lock
有问题。您可以尝试 rm
两者并重新 运行 yarn install
按照以下步骤操作
- 删除
yarn.lock
文件
添加一个新的Aptfile
,内容如下
gcc
build-essential
使用以下命令添加 apt
buildpack
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
完成后,再次推送到 heroku,现在它应该可以工作了
我有一个表单,我可以在其中提交图片并将它们上传到 Firebase。我在本地构建了这个项目,但是当我将它推送到 Heroku 时它就崩溃了。
快递:
var gcs = require( 'multer-gcs' );
var storage = gcs({
filename : function( req, file, cb ) {
cb( null, file.fieldname + '-' + Date.now() );
},
bucket : 'mybucket.appspot.com', // Required : bucket name to upload
projectId : 'mybucket', // Required : Google project ID
keyFilename : './mybucket-firebase-adminsdk-4oyba-xee555bbgr.json', // Required : JSON credentials file for Google Cloud Storage
acl : 'publicread' // Optional : Defaults to private
});
const multer = require('multer');
var upload = multer({storage: storage});
app.post('/sell', upload.any(), homeController.postSellPage);
第一个错误代码(来自 Heroku Logs
):
Error: Cannot find module 'multer-gcs'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at Object.<anonymous> (/app/app.js:22:11)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at tryModuleLoad (module.js:446:12)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
然后我 运行 以下内容以更新我的 package.json
:npm install multer-gcs --save
,并安装了它,同时给我这条消息:
deprecated gcloud@0.36.0: gcloud has been renamed to google-cloud. To get new features and bug fixes, you must use the new package.
我不知道如何处理该消息,所以除了在提交新 package.json
后重新推送到 heroku 之外,我什么也没做。我遇到以下问题:
Build failed
Outdated Yarn lockfile
Your application contains a Yarn lockfile (yarn.lock) which does not
match the dependencies in package.json. This can happen if you use npm
to install or update a dependency instead of Yarn.
Please run the following command in your application directory and check
in the new yarn.lock file:
$ yarn install
$ git add yarn.lock
$ git commit -m "Updated Yarn lockfile"
$ git push heroku master
https://kb.heroku.com/why-is-my-node-js-build-failing-because-of-an-outdated-yarn-lockfile
然后我 运行 yarn install
,但得到了
The engine "node" is incompatible with this module. Expected version "6.9.5".
Found incompatible module
Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
所以我查看并在 package.json 中有以下内容,其中包括节点 6.9.5
,所以我认为我在这方面没问题。
"engines": {
"node": "6.9.5",
"npm": "4.6.1",
"yarn": "1.3.2"
},
然后我 运行 yarn install --ignore-engines
,基于关于同一问题的 posting。这给了我以下内容:
/Users/user/path/node_modules/gcloud/node_modules/grpc: Command failed.
Exit code: 127
Command: ./node_modules/.bin/node-pre-gyp install --fallback-to-build
我尝试了 运行 这个命令 npm install --unsafe-perm
,基于另一个 posting,但是 grpc
又出现了这个问题。
我希望得到任何关于如何让 heroku 进入 accept/run 构建的帮助,因为我在这个问题上遇到了困难。如果需要任何说明,请告诉我。
根据要求,package.json
:
{
"name": "App Name",
"version": "0.0.2",
"description": "Amazing Application",
"engines": {
"node": "6.9.5",
"npm": "4.6.1",
"yarn": "1.3.2"
},
"repository": {
"type": "git",
"url": "https://github.com/amazing_app.git"
},
"author": "Example",
"license": "Example",
"scripts": {
"start": "node app.js",
"test": "mocha --reporter spec",
"postinstall": "npm rebuild node-sass"
},
"dependencies": {
"aws-sdk": "^2.46.0",
"bcrypt-nodejs": "^0.0.3",
"bluebird": "^3.4.7",
"body-parser": "^1.15.2",
"chalk": "^1.1.3",
"cheerio": "^0.22.0",
"clockwork": "^0.1.4",
"compression": "^1.6.2",
"connect-mongo": "^1.3.2",
"dotenv": "^4.0.0",
"errorhandler": "^1.4.3",
"express": "^4.14.0",
"express-flash": "^0.0.2",
"express-session": "^1.14.2",
"express-status-monitor": "^0.1.5",
"express-validator": "^3.1.2",
"fbgraph": "^1.3.0",
"firebase": "^3.9.0",
"firebase-admin": "^4.2.1",
"github": "^9.2.0",
"grpc": "1.3.8",
"instagram-node": "^0.5.8",
"lastfm": "^0.9.2",
"lob": "^3.9.0",
"lusca": "^1.4.1",
"mongoose": "^4.6.6",
"morgan": "^1.7.0",
"multer": "^1.3.0",
"multer-gcs": "^1.0.2",
"node-base64-image": "^1.0.3",
"node-foursquare": "^0.3.0",
"node-linkedin": "^0.5.4",
"node-sass-middleware": "^0.11.0",
"nodemailer": "^3.1.7",
"passport": "0.3.2",
"passport-facebook": "^2.1.1",
"passport-github": "^1.1.0",
"passport-google-oauth": "^1.0.0",
"passport-instagram": "^1.0.0",
"passport-linkedin-oauth2": "^1.4.1",
"passport-local": "^1.0.0",
"passport-oauth": "^1.0.0",
"passport-openid": "^0.4.0",
"passport-twitter": "^1.0.4",
"paypal-rest-sdk": "^1.7.0",
"pug": "^2.0.0-beta6",
"request": "^2.78.0",
"stripe": "^4.12.0",
"tumblr.js": "^1.1.1",
"twilio": "^3.3.1-edge",
"twit": "^2.2.5",
"validator": "^7.0.0"
},
"devDependencies": {
"chai": "^3.5.0",
"eslint": "^3.9.1",
"eslint-config-airbnb-base": "^11.0.0",
"eslint-plugin-import": "^2.1.0",
"mocha": "^3.1.2",
"supertest": "^3.0.0"
},
"eslintConfig": {
"extends": "airbnb-base",
"rules": {
"comma-dangle": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"no-shadow": 0,
"no-console": 0,
"no-plusplus": 0
}
}
}
**注意:**只有当我取消注释 Express
下的内容(如上所示)时才会中断。
更新:
当我将 AWS 与 Multer var multerS3 = require('multer-s3');var s3 = new aws.S3({});
一起使用时,应用程序将成功 post 到 Heroku var multerS3 = require('multer-s3');var s3 = new aws.S3({});
所以它必须与 GCS 及其依赖项有关
不是 100% 确定,但是您需要 包含 yarn.lock
文件吗?我知道它会将您的依赖项锁定在您使用的确切版本上,但在大多数情况下没有它应该没问题吗?
如果你git rm yarn.lock
理论上heroku可能更喜欢你。
也有可能是您的 node_modules 中的某些内容以某种方式损坏(我不是 100% 确定这是如何发生的)或者您的 yarn.lock
有问题。您可以尝试 rm
两者并重新 运行 yarn install
按照以下步骤操作
- 删除
yarn.lock
文件 添加一个新的
Aptfile
,内容如下gcc build-essential
使用以下命令添加
apt
buildpackheroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
完成后,再次推送到 heroku,现在它应该可以工作了