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...)