Closed keerthanapraskash closed 10 months ago
graphql-upload
is a pure ESM package, that works with how Node.js runs ESM:
https://nodejs.org/api/esm.html#interoperability-with-commonjs
You can learn more about working with pure ESM packages here:
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
You can't require
this package, you can only import
it.
You are also making a second error; resulting in ERR_PACKAGE_PATH_NOT_EXPORTED
. You are not deep importing from the relevant module; this package doesn't have a main index module. The publicly exported modules are documented here:
https://github.com/jaydenseric/graphql-upload/tree/v16.0.2#exports
Hope that helps! Next time, please try searching the issues for similar ones raised in the past.
@jaydenseric
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in D:\CRUD-APIS\original-issue\node_modules\graphql-upload\package.json
I'm new to Graphql. I am trying to upload a file using Graphql. I'm following the code written in the official doc of appollo but getting this error.
`const express = require('express'); const { ApolloServer, gql } = require('apollo-server-express'); const { GraphQLUpload, graphqlUploadExpress, // A Koa implementation is also exported. } = require('graphql-upload');
// const GraphQLUpload = require("graphql-upload/GraphQLUpload.js"); // const graphqlUploadExpress= require("graphql-upload/graphqlUploadExpress.js"); const { finished } = require('stream/promises'); const { ApolloServerPluginLandingPageLocalDefault } = require('apollo-server-core');
const typeDefs = gql`
scalar Upload
type File { filename: String! mimetype: String! encoding: String! }
type Query {
}
type Mutation {
} `;
const resolvers = {
Upload: GraphQLUpload,
Mutation: { singleUpload: async (parent, { file }) => { const { createReadStream, filename, mimetype, encoding } = await file;
}, };
async function startServer() { const server = new ApolloServer({ typeDefs, resolvers,
}); await server.start();
const app = express();
app.use(graphqlUploadExpress());
server.applyMiddleware({ app });
await new Promise((r) => app.listen({ port: 4000 }, r));
console.log(
🚀 Server ready at http://localhost:4000${server.graphqlPath}
); }startServer();`