我正在使用 Typescript 开发带有 graphql 和 express 的后端 API。我正在使用 webpack 来管理项目开发和构建过程。
我正在使用 raw-loader 将文件中的 graphql 模式和 sql 查询作为字符串加载。
目前我面临一些我不太了解的问题。
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/,
},
};
服务器.ts
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';
const app = express();
app.use(morgan('combined'));
app.use(bodyParser.json());
app.use(
'/graphql',
graphqlHTTP({
schema: affairSchema,
rootValue: affairRoot,
graphiql: true,
})
);
const port = process.env.PORT || 4000;
app.listen(port, () => console.log('Server waiting on ', port));
错误:
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
ERROR in ./node_modules/graphql/index.mjs
88:0-148:42 Can't reexport the named export 'valueFromAST' from non EcmaScript module (only default export is available)
@ ./node_modules/graphql/index.mjs
@ ./src/schemas/index.ts
@ ./server.ts
ERROR in ./node_modules/graphql/index.mjs
88:0-148:42 Can't reexport the named export 'valueFromASTUntyped' from non EcmaScript module (only default export is available)
@ ./node_modules/graphql/index.mjs
@ ./src/schemas/index.ts
@ ./server.ts
ERROR in C:\Users\houssem\Projects\ctc\services\affairs\src\schemas\index.ts
./src/schemas/index.ts
[tsl] ERROR in C:\Users\houssem\Projects\ctc\services\affairs\src\schemas\index.ts(5,28)
TS2307: Cannot find module './affairs.gql'.
ERROR in C:\Users\houssem\Projects\ctc\services\affairs\services\database\engineer.ts
./services/database/engineer.ts
[tsl] ERROR in C:\Users\houssem\Projects\ctc\services\affairs\services\database\engineer.ts(7,19)
TS2307: Cannot find module './engineer.sql'.
.
.
.
.
.