Join the conversation

Sign in to join this conversation, and others like it, in the communities you care about.

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

ZEIT / General

Can't deploy my NodeJS app to Zeit

Can't deploy my NodeJS app to Zeit

ZEIT / General · December 2, 2018 at 10:39pm
I'm trying to deploy my NodeJS application to Zeit. I've followed this (https://github.com/DevMountain/Hosting-React-Zeit) instruction and after npm run deploy I'm getting "Invalid Host header" error. I saw other (https://stackoverflow.com/questions/52814519/invalid-host-header-in-a-react-app-deployed-to-ibm-cloud) instructions, but they're using different stack on technologies, so I can't really apply it to my situation. The only answer (https://zeit.co/vpicone/portfolio/ppiiegssbe/source?f=README.md) I've found is about the same issue with proxy, and to fix it they want to create .env.development file and put there HOST=mypublicdevhost.com. So, my question is what is HOST here or is there any other way to fix it? Right now status of my app is "READY".

December 2, 2018 at 10:48pm

Can you please post your now.json? That repo is old, maybe with "version": 1 it can work...

Edited
  • reply
  • like

Also I would advise you to use this: https://github.com/react-boilerplate/react-boilerplate, with the following configuration:

now.json:

{
  "version": 2,
  "builds": [
    {"src": "package.json", "use": "@now/static-build", "config": {"distDir": "build"}}
  ]
}

add a "now-build" script to package.json:

"now-build": "cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress --hide-modules --display-optimization-bailout"

Done!

  • reply
  • like

I don't think I ever saw it's required to make now.json file

  • reply
  • like

I don't have React app, it's only Node.js right now

  • reply
  • like

So, I've done everything you said and tried to do npm run now-build and it gave me an error:

  • reply
  • like

sh: cross-env: command not found

npm ERR! file sh

npm ERR! code ELIFECYCLE

npm ERR! errno ENOENT

npm ERR! syscall spawn

npm ERR! aivazovsky@0.1.0 now-build: `cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress --hide-modules --display-optimization-bailout`

npm ERR! spawn ENOENT

npm ERR!

npm ERR! Failed at the aivazovsky@0.1.0 now-build script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

npm ERR! /Users/in43sh/.npm/_logs/2018-12-02T23_17_37_819Z-debug.log

  • reply
  • like

Do you know what might be the problem? I think something is wrong with my .env, I have .env for development and .env.prod for production and in my .env.prod I have NODE_ENV=production

  • reply
  • like

December 3, 2018 at 8:24pm

Sergey, can you share a little PoC with me or some code that I can see to give you my thoughts?

  • reply
  • like

December 5, 2018 at 7:04am

Sure, what exactly do I need to share?

  • reply
  • like

December 5, 2018 at 10:14am

Just a repo with minimal amount of code, to see if I can point to the culprit...

  • reply
  • like

December 6, 2018 at 7:19am

December 6, 2018 at 9:53am

Why this line: https://github.com/in43sh/aivazovsky/blob/master/package.json#L35 is different from your actual build setup? Shouldn't it be "NODE_ENV=production react-scripts build"?

Edited
  • reply
  • like

Why this line: https://github.com/in43sh/aivazovsky/blob/master/package.json#L35 is different from your actual build setup? Shouldn't it be "NODE_ENV=production react-scripts build"?

Ok, thank you, I changed it to react-scripts build instead and now I'm getting the same error, but with react-scripts build instead in the path.

  • reply
  • like

Here's the copy of the log file:

  • reply
  • like

0 info it worked if it ends with ok

1 verbose cli [ '/usr/local/bin/node',

1 verbose cli '/usr/local/bin/npm',

1 verbose cli 'run',

1 verbose cli 'now-build' ]

2 info using npm@6.4.1

3 info using node@v10.12.0

4 verbose run-script [ 'prenow-build', 'now-build', 'postnow-build' ]

5 info lifecycle aivazovsky@0.1.0~prenow-build: aivazovsky@0.1.0

6 info lifecycle aivazovsky@0.1.0~now-build: aivazovsky@0.1.0

7 verbose lifecycle aivazovsky@0.1.0~now-build: unsafe-perm in lifecycle true

8 verbose lifecycle aivazovsky@0.1.0~now-build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/in43sh/web-dev/devmtn/projects/aivazovsky/node_modules/.bin:/Applications/MAMP/bin/php/php7.2.8/bin:/Users/in43sh/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MAMP/bin/php/php7.2.8/bin:/Users/in43sh/.rbenv/shims

9 verbose lifecycle aivazovsky@0.1.0~now-build: CWD: /Users/in43sh/web-dev/devmtn/projects/aivazovsky

10 silly lifecycle aivazovsky@0.1.0~now-build: Args: [ '-c', 'cross-env NODE_ENV=production react-scripts build' ]

11 info lifecycle aivazovsky@0.1.0~now-build: Failed to exec now-build script

12 verbose stack Error: aivazovsky@0.1.0 now-build: `cross-env NODE_ENV=production react-scripts build`

12 verbose stack spawn ENOENT

12 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)

12 verbose stack at ChildProcess.emit (events.js:182:13)

12 verbose stack at maybeClose (internal/child_process.js:962:16)

12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)

13 verbose pkgid aivazovsky@0.1.0

14 verbose cwd /Users/in43sh/web-dev/devmtn/projects/aivazovsky

15 verbose Darwin 18.2.0

16 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "now-build"

17 verbose node v10.12.0

18 verbose npm v6.4.1

19 error file sh

20 error code ELIFECYCLE

21 error errno ENOENT

22 error syscall spawn

23 error aivazovsky@0.1.0 now-build: `cross-env NODE_ENV=production react-scripts build`

23 error spawn ENOENT

24 error Failed at the aivazovsky@0.1.0 now-build script.

24 error This is probably not a problem with npm. There is likely additional logging output above.

25 verbose exit [ 1, true ]

  • reply
  • like

Tell me if this is what you expect ^

  • reply
  • like

now.json:

{
  "version": 2,
  "builds": [
    {"src": "package.json", "use": "@now/static-build", "config": {"distDir": "build"}}
  ],
  "routes": [
    {"src": "^/static/(.*)", "dest": "/static/$1"}
  ]
}

Source: https://github.com/zeit/now-examples/tree/master/create-react-app

  • reply
  • like

December 6, 2018 at 11:01pm

oh wow thank you! I didn't do anything, but it suddently started working. I accidentally deleted my db from heroku, so it's supposed to be broken now. again, thank you!

  • reply
  • like

I honestly don't know why it started working

  • reply
  • like

Well, we updated our builders and/or ncc, maybe it is that!

Edited
  • reply
  • like

thank you much!

  • reply
  • like
Your message here...

*bold*_italic_`code````codeblock```