question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with upload images in Heroku

See original GitHub issue

Bug report

I’m having trouble uploading images using Cloudinary Adapter in Production (Heroku)

To Reproduce

Steps to reproduce the behaviour. Please provide code snippets or a repository:

  1. Set secureCookies: false
  2. Set app.set("trust proxy", 1);
  3. Deploy to Heroku
  4. Try upload image
  5. In console show this error

[Network error]: ServerParseError: JSON.parse: unexpected character at line 1 column 1 of the JSON data TypeError: e is undefined

In remote console

2020-01-17T14:03:17.474496+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/admin/api" host=jumpittlabs-site-cms.herokuapp.com request_id=14e94647-88b8-43ef-9329-1aa1de849451 fwd="152.231.93.178" dyno=web.1 connect=1ms service=345ms status=503 bytes=0 protocol=https

Expected behaviour

I want upload image as it does in development

System information

  • OS: Heroku?
  • Firefox, Safari and Chrome

Screenshot

https://i.imgur.com/AyKyP7z.png

Aditional information

This is my index.js

require("dotenv").config();
const { Keystone } = require("@keystonejs/keystone");
const { PasswordAuthStrategy } = require("@keystonejs/auth-password");
const { GraphQLApp } = require("@keystonejs/app-graphql");
const { AdminUIApp } = require("@keystonejs/app-admin-ui");
const { MongooseAdapter: Adapter } = require("@keystonejs/adapter-mongoose");
const expressSession = require('express-session');
const MongoStoreMaker = require("connect-mongo");
const User = require("./models/User");
const Member = require("./models/Member");
const Project = require("./models/Project");
const Department = require("./models/Department");
const bodyParser = require("body-parser");
const { makeANiceEmail, transport } = require("./src/mail");
const MongoStore = MongoStoreMaker(expressSession);
const { ExpressApp } = require("@keystonejs-contrib/app-express");

const keystone = new Keystone({
  name: "jumpittlabs-site-cms",
  adapter: new Adapter(),
  sessionStore: new MongoStore({
    url: process.env.DATABASE_URL
  }),
  secureCookies: false
});

keystone.createList("User", User);
keystone.createList("Member", Member);
keystone.createList("Project", Project);
keystone.createList("Department", Department);

const authStrategy = keystone.createAuthStrategy({
  type: PasswordAuthStrategy,
  list: "User"
});

module.exports = {
  keystone,
  apps: [
    new GraphQLApp(),
    new AdminUIApp({ authStrategy }),
    new ExpressApp(app => {
      app.use(bodyParser.urlencoded({ extended: true }));
      app.use(bodyParser.json());
      app.post("/email", async function (req, res) {
        await transport.sendMail({
          from: "'Mr. Fox 🦊' <user@website.com>",
          to: "alvaaz_@hotmail.com",
          subject: "Hello World",
          text: "Hello World?",
          html: makeANiceEmail
        }, (error, info) => {
          if (error) {
            return console.log(error);
          }
          console.log("Message sent: %s", info.messageId);
          res.sendStatus(200);
        });
      });
    })
  ],
  configureExpress: app => {
    if (process.env.NODE_ENV !== "development") {
      app.set("trust proxy", 1);
    }
  }
};

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jenriquejrcommented, Apr 20, 2020

This fixed a similar issue for me. The error in the logs was the following: EDIT: (This only happened while uploading images)

"name":"graphql"
"message": "Maximum call stack size exceeded"
...
"name":"GraphQLError"
"errors":[
      {
        "name":"RangeError",
        "message":"Maximum call stack size exceeded",
        "stack": "ReadStream.open (node_modules/fs-capacitor/lib/index.js:90:11)"
      }
],

fixed by updating the engines on the package.json

{
  "engines": {
    "node": "12.16.x"
  }
}

thanks @alvaaz

1reaction
alvaazcommented, Feb 24, 2020

Yep. I fix it for now, setting node version to 12.13.x in Heroku.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image upload functionality not working on deployed Heroku ...
Heroku is not suitable for persistent storage of data, the uploaded pictures would be deleted after a while (when the dyno is restarted) ......
Read more >
Why photo not upload when i deploy on heroku
I made a MERN project,there for my backend i use multer for form upload. It work perfectly in my local machine and posted...
Read more >
Why are my file uploads missing/deleted from the Application
Issue. Files are uploaded to the app but then disappear or are deleted after a while. Resolution. The Heroku filesystem is ephemeral -...
Read more >
Problem with upload images in Heroku · Issue #2256 - GitHub
Bug report I'm having trouble uploading images using Cloudinary Adapter in Production (Heroku) To Reproduce Steps to reproduce the behaviour.
Read more >
image upload works locally, but the deployed version ... - Reddit
So it's it's not logging any error in the console. Images are uploaded on AWS. It works locally but not on heroku ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found