0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【graphql-upload】export in package.json causes import failuresの解消方法

Last updated at Posted at 2022-10-19

はじめに

ファイルをアップロードする関係上、multipart/form-dataをリクエストで受け取る必要があったのでgraphql-uploadを利用したが No "main" export in package.json causes import failuresエラーが発生したので調査した結果をまとめています。

環境

graphql-upload latest(16.0.2)で発生

graphql-uploadREADME.mdに記載のあるRequirementsの通りにコンパイルオプションを変更した

結論

graphql-upload-minimalで代用しました
こちらはgraphql-uploadをフォークされて作られたものなので同じように使用することが可能です

Simply said, if you're not ready for the enlightenment, just stick with the @13 version 😄 or use graphql-upload-minimal package

実際に利用する場合は以下の形式でインポート先を変更するだけで利用が可能です
NestJSを利用していますがNode.js等で利用される場合は構文を読み替えていただければ同様の結果を得ることができると思います。

app.module.ts
import { MiddlewareConsumer, Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { PrismaModule } from './prisma/prisma.module'
import { GraphQLModule } from '@nestjs/graphql'
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'
import * as Process from 'process'
import * as path from 'path'
import { LoggerModule } from 'nestjs-pino'
import { ConfigModule } from '@nestjs/config'
import { AuthorModule } from './author/author.module'
import { AppService } from './app.service'
import configuration from './common/config/configuration'
import { graphqlUploadExpress } from 'graphql-upload-minimal'


@Module({
  imports: [
    LoggerModule.forRoot(),
    PrismaModule,
    ConfigModule.forRoot({
      isGlobal: true,
      load: [configuration],
    }),
    AuthorModule,
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      autoSchemaFile: path.join(process.cwd(), 'src/graphql/schema.gql'),
      sortSchema: true,
    }),
    CustomJwtModule,
    Auth0Module,
  ],
  providers: [AppService],
  controllers: [AppController],
})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(graphqlUploadExpress()).forRoutes('graphql')
  }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?