Stretch0
Stretch0

Reputation: 9241

Transpiling next.js server code

I have a fresh install of Next.js and am wanting to be able to use import and async/await etc.

I have updated my .babelrc

{
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["."],
        "alias": {
          "styles": "./styles"
        },
        "cwd": "babelrc"
      }
    ],
    [
      "wrap-in-js",
      {
        "extensions": ["css$"]
      }
    ]
  ],
  "presets": [
    "next/babel",
    "es2015",
    "stage-0",
  ],
  "ignore": []
}

I assume I need to update some config to ./server.js?

Also how do I get around starting my app as I can point my start script to run from ./dist/server but I believe the server needs to run to be able to run a build?

Upvotes: 1

Views: 1356

Answers (1)

Nathan Friedly
Nathan Friedly

Reputation: 8146

I have a fresh install of Next.js and am wanting to be able to use import and async/await etc.

I believe async/await works on the current release without an modification, but dynamic import requires the v3 beta:

npm install next.js@beta

See https://zeit.co/blog/next3-preview

Also how do I get around starting my app as I can point my start script to run from ./dist/server but I believe the server needs to run to be able to run a build?

Normally, you run npm run dev (which is aliased to next) for development and npm run build; npm start (which aliases to next build; next start) for production. You wouldn't directly run any JS file.

If you want to run a custom server, then you would start your server file directly (node myserver.js or whatever) and have it start next programatically. See https://github.com/zeit/next.js/tree/master#custom-server-and-routing for more info on that.

Upvotes: 1

Related Questions