Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

310
Vistas
Node server not working in monorepo with babel compiler

I have a monorepo with the following folder structure.

packages/
    - server
        - src
            - index.js
        - build
    - lib1
    - lib2

My node server uses express and graphql, with a very simple setup.

index.js

const start = async () => {
  const server = new ApolloServer({
    schema: clientSchema,
    tracing: true,
    introspection: process.env.NODE_ENV !== "production",
  });

  await server.start()

  const app = express();

  app.use(express.json({limit: '10mb'}));
  app.use(express.urlencoded({limit: '10mb', extended: true}));
  server.applyMiddleware({ app });

  app.listen({ port }, () =>
    console.log(`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`)
  );
}

I am using babel to transpile the node server using a .babelrc file with the following config

{
  "presets": ["@babel/preset-env"],
  "plugins": ["@babel/plugin-transform-runtime"]
}

lib1 and lib2 are packages using import and export syntax.

When I build the node server using something like babel -d ./build ./src and then start the server using node ./build/index.js

I am presented with the error SyntaxError: Cannot use import statement outside a module for one of the files in package/lib1.

Now I have gotten this to work by changing index.js in the server package to be like the example below however im finding the server uses a lot of memory and takes a long time when initially starting up which makes my Heroku server cost really expensive as it will crash due to memory quotas going past 1GB.

require('@babel/register')({
  presets: ['@babel/preset-env'],
  ignore: ['node_modules'],
  plugins: [
    "@babel/plugin-transform-runtime"
  ]
});

// Import the rest of our application.
module.exports = require('./server.js');
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda