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.

How to deploy Next.js with Express and external Babel?

See original GitHub issue

It is my first application with Next.js and I am facing problems to deploy the project to Heroku. I am using Express server and a external .babelrc file.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

No errors building/running project in Heroku.

Current Behavior

I am running yarn build and then git init / add / commit / push in .next/dist folder and copying package.json into it too.

Context

This is my scripts from package.json:

"scripts": {
    "start": "NODE_ENV=production node server/server.js",
    "dev": "nodemon -w server server/server.js --exec babel-node",
    "build": "next build && babel server -d .next/dist/server",
    "lint": "eslint --fix components lib pages server **/*.js",
    "snyk": "snyk test",
    "heroku-postbuild": "next build && babel server -d .next/dist/server"
  }

next.config.js:

module.exports = {
  webpack: (config, { dev }) => {
    // For the development version, we'll use React.
    // Because, it support react hot loading and so on.
    if (dev) {
      return config;
    }

    config.resolve.alias = {
      react: 'inferno-compat',
      'react-dom': 'inferno-compat'
    };
    return config;
  }
};

And the .babelrc:

{
  "presets": [
    [
      "next/babel",
      {
        "preset-env": {
          "modules": "commonjs"
        }
      }
    ]
  ],
  "env": {
    "development": {
      "plugins": ["inline-dotenv"]
    },
    "production": {
      "plugins": ["transform-inline-environment-variables"]
    }
  }
}

Your Environment

Tech Version
next 6.0.1
node 9.5.0
@babe/* ^7

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
timneutkenscommented, May 14, 2018

I’m not sure what the issue is here.

I am running yarn build and then git init / add / commit / push in .next/dist folder and copying package.json into it too.

This sounds like a weird thing to do.

Also you’re building your custom server to .next/dist and then starting it from server/server.js.

0reactions
timneutkenscommented, Nov 7, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deploy Next.js with Express and external Babel? #4344
It is my first application with Next.js and I am facing problems to deploy the project to Heroku. I am using Express server...
Read more >
Advanced Features: Customizing Babel Config - Next.js
Extend the babel preset added by Next.js with your own configs. ... To start, you only need to define a .babelrc file (or...
Read more >
Set Up Next.js with a Custom Express Server + Typescript
In this post, I will walk you through how to make a Next.js application handled by a custom Express server with Typescript.
Read more >
Adding Babel presets and plugins in Next.js - Netlify
But, it's nice and simple to add custom presets and plugins, if you so desire! First, make a file at the root of...
Read more >
Using external babel configuration breaks node/react app
//.babelrc { "presets": [ [ "next/babel" ] ] }.
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