How to deploy Next.js with Express and external Babel?
See original GitHub issueIt 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:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not sure what the issue is here.
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.
@ElvenMonky read this issue: https://github.com/zeit/next.js/issues/4496