getting TypeScript configured with webpack

I am currently using Typescript to develop a back-end API utilizing graphql and express. To manage the project development and building process, I have implemented webpack.

As part of my setup, I am employing raw-loader in order to load graphql schemas and sql queries from external files as strings.

However, at this moment, I am encountering some challenges that are proving tricky for me to comprehend fully.

Below are snippets from my webpack configuration file (webpack.config.js):

const path = require('path');

module.exports = {
  target: 'node',
  entry: {
    server: path.resolve(__dirname, 'server.ts'),
  },
  output: {
    filename: 'server.js',
    path: path.resolve(__dirname, 'dist'),
  },
  devtool: 'source-map',
  module: {
    rules: [
      {
        test: /\.(gql|sql)$/,
        loader: 'raw-loader',
      },
      {
        test: /\.ts$/,
        loader: 'ts-loader',
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  watch: {
    ignored: /node_modues/,
  },
};

In addition, here is a snippet from my server file (server.ts) showing how I am setting up the Express server with graphql:

import express from 'express';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import graphqlHTTP from 'express-graphql';

import { affairSchema } from './src/schemas';
import affairRoot from './src/resolvers/affairs';

// Server setup code goes here...

app.listen(port, () => console.log('Server waiting on ', port));

The errors I am currently facing include:

ERROR in ./node_modules/graphql/index.mjs
88:0-148:42 Can't reexport the named export 'typeFromAST' from non EcmaScript module (only default export is available)
 @ ./node_modules/graphql/index.mjs
 @ ./src/schemas/index.ts
 @ ./server.ts

(Additional error messages continue...)

Answer №1

Eliminate bundling of node modules by utilizing webpack-node-externals. This approach can effectively resolve errors, although it necessitates the presence of node_modules during application execution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When running 'npm run dev', an error occurred after the SizeLimitsPlugin emitted at 98%. The specific dependency that was

I encountered an issue while trying to incorporate Google Maps into my Laravel project and received the following error message after running npm run dev: 98% after emitting SizeLimitsPlugin ERROR Failed to compile with 1 errors 10:52:34 PM This dependen ...

How can I dynamically render a component using VueJS?

Incorporating a component named CanvasComp from my components folder, I am rendering it on the template like <CanvasComp :jsoData="data"/> to send jsonData to the component. However, I am seeking a way to dynamically render this component w ...

How can Typescript elevate your use of the IFrame API?

Here is a code snippet that performs the following actions: let doc = this.iframe.contentDocument || this.iframe.contentWindow; let content = `...` doc!.open(); doc!.write(content); doc!.close(); Despite this, the Typescript linter thr ...

Sending data and redirecting to a new URL by linking multiple responses together

As a beginner in javascript, I wanted to confirm if my code is appropriate. I am currently using JavaScript to handle a PUT request. My main goal is to return the updated Sequelize model as a response and then redirect the user back to the local /. Can I ...

Showcasing a single object in an IONIC/Angular application using the ngIF directive

I am in need of assistance as I have encountered an issue. Essentially, I am fetching an object from an external API (Strapi) using the GET method, but when attempting to display it on Views with ngIF, it fails to show up. Below is the code snippet: word ...

Is it possible to turn off security features for a Heroku Postgres database?

My project doesn't involve sensitive data, so I'm not concerned about security vulnerabilities. I believe the issue lies in the connection between the App/server and the DB. I've searched on Youtube and Google for solutions, but the informa ...

Submitting the object in the correct format for the Firebase database

My goal is to structure the Firebase database in the following way: "thumbnails": { "72": "http://url.to.72px.thumbnail", "144": "http://url.to.144px.thumbnail" } However, I am struggling to correctly set the keys '72' and '144&apos ...

Should the date be formatted prior to being submitted to MongoDB?

This is the schema I am currently working with: created_at: { type: Date, default: Date.now }, updated_at: { type: Date, default: Date.now } I am looking for a way to format the Date.now output to HH:MM before sending it to the database. It woul ...

Is it possible to track when a user switches to a different component in Angular?

I'm looking to set up a confirmation popup when the user attempts to navigate to a different page. I've come across information about hostListener and canActivate, but I'm not exactly sure how to begin! Any guidance would be greatly apprecia ...

Change the value of the checked property to modify the checked status

This is a miniCalculator project. In this mini calculator, I am trying to calculate the operation when the "calculate" button is pressed. However, in order for the calculations to run correctly in the operations.component.ts file, I need to toggle the val ...

With NodeJs, Mongoose refrains from storing any data in the database

Recently, I encountered a puzzling issue with my code designed to store superhero names and powers in a database. Despite all the connections functioning correctly, I faced an unexpected challenge. When running mongod, I utilized the --dbpath C:/nodeproje ...

Utilizing Pug to Insert Images in Email Messages (Integrating them as Content, not Attachments)

Does anyone know how to include an image in the body of an email without it being sent as an attachment? I have the image in my template, but it doesn't show up when I send the email. I'm new to this and could use some guidance. ...

Node.js application using excessive CPU resources

I have a custom ExpressJS application built on Node.js, running on IISNode within a Windows Server 2016 virtual machine. The VM is equipped with 4 cores and 32GB of memory, allowing me to allocate one process per core. As a result, my application consists ...

Utilizing an Angular Service within the main.ts script

My main.ts file currently has the following code snippet: declare const require; const translations = require("raw-loader!./locale/messages.de.xlf"); platformBrowserDynamic().bootstrapModule(AppModule, { providers: [ { provide: TRANSLATIONS, useVa ...

How can I respond with an error HTTP status code in Express utilizing Node.js?

While working on the login page, I encountered an issue with sending credentials from Angular to Express through a GET request. My goal is to have Express send a response if the data is found in the database, which can be handled by Angular. However, if th ...

Why does the "xxx" module keep repeating the error message: "Module not found"?

Currently experimenting with a tutorial utilizing express.js to create a simple web server. Issue: Each time I execute the js file, I encounter the recurring error indicating that module "x," then module "y," and then module "z" is not found. It appears th ...

Problem encountered with displaying a component in Laravel Nova following the completion of dependency updates

Hey there, Stack Overflow community! I'm currently struggling with a rendering issue in Laravel Nova following some recent updates to dependencies within the project. Whenever I attempt to access the component in Laravel Nova, an error message pops u ...

Creating a second optional generic parameter in TypeScript

I'm having trouble with TypeScript generics My issue is as follows: I have an interface called 'Column' and a function called makeColumn to create a new column. I want to only set the first generic (UserModel), where the accessor must be a ...

The value returned by a mocked Jest function is ignored, while the implemented function is not invoked

Having an issue with mocking the getToken function within my fetchData method in handler.ts while working with ts-jest. I specifically want to mock the response from getToken to avoid making the axios request when testing the fetchData method. However, des ...

Guide on showing a placeholder image in Angular2 when the image is missing

I am trying to figure out how to display a default image when the image source coming from the backend is null. Can someone assist me with this issue? If the image part is null, then I want to display the following image: "../assets/images/msg.png" Conso ...