Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!