1

I'm deploying a next app, but when I try to run it I get the following error:

import React, { useState, useEffect } from 'react';
       ^^^^^

SyntaxError: Unexpected identifier

It seems as if Node is not identifying the code. I understand that that is why we have to use Babel, so Node can understand ES6 sintax. I don't think I have to add Babel configuration since I didn't have to do that when I was running my NextJS project locally, but I actually tried that anyway and got an error when trying to build my app.

This seems to be an issue related with the Node environment itself and not Next, but I was wondering if somebody has encounter something like this.

I am deploying this site using Plesk, and it seems as if Plesk uses PhusionPassenger to serve the app.

Carlos G
  • 311
  • 2
  • 13
  • Node supports ES6 and many experimental features natively, it most absolutely doesn't need Babel. What's your node version? Try `node -v` – Klaycon Mar 05 '20 at 17:08
  • According to Plesk, the node version is 12.4.0 – Carlos G Mar 05 '20 at 17:16
  • @Klaycon is not entirely right in their statement. Node prior to v13 used `require` from CommonJS by default and would not recognize import/export statements. I use Babel with Node v12, although it's not the only way to go about this. Read more here: https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node. – Avius Mar 05 '20 at 18:05

1 Answers1

0

My error was the Application Startup file. It should be "node_modules/.bin/next" and not "pages/index.js".

Carlos G
  • 311
  • 2
  • 13