jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

[v15.0.2] No "exports" main defined in /.../node_modules/graphql-upload/package.json #325

Closed wojtekKrol closed 2 years ago

wojtekKrol commented 2 years ago

Im migrating from apollo v2 to v3 and wanted to update graphql-upload and occur this error

internal/modules/cjs/loader.js:456
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/wkrol/vazco/fruitful-insights/server2/node_modules/graphql-upload/package.json
    at new NodeError (internal/errors.js:322:7)
    at throwExportsNotFound (internal/modules/esm/resolve.js:322:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:545:3)
    at resolveExports (internal/modules/cjs/loader.js:450:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
    at Function.wrappedResolveFilename [as _resolveFilename] (/home/wkrol/vazco/fruitful-insights/server2/node_modules/newrelic/lib/shimmer.js:364:42)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Function.wrappedLoad [as _load] (/home/wkrol/vazco/fruitful-insights/server2/node_modules/newrelic/lib/shimmer.js:373:24)
    at Module.require (internal/modules/cjs/loader.js:974:19) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

image

My packages are:

   "graphql-upload": "15.0.2",
    "@types/graphql-upload": "8.0.11",

image

I saw this thread but these solutions do not work for me, could someone tell me how to make it work?

jaydenseric commented 2 years ago

Please try uninstalling @types/graphql-upload; graphql-upload has it's own types built in now via TypeScript JSDoc comments.

wojtekKrol commented 2 years ago

@jaydenseric I've removed it from package.json and then run npm ci. Error remains image

jaydenseric commented 2 years ago

Does your project TypeScript config have compilerOptions.module set to nodenext?

wojtekKrol commented 2 years ago

It's set to:


  "compilerOptions": {
    "module": "commonjs",
     ...

my other main packages versions:

    "apollo-server-core": "^3.9.0",
    "apollo-server-express": "3.9.0",
    "graphql": "^15.3.0",

in case it's matter

jaydenseric commented 2 years ago

It should be set to nodenext (or node16 if you want to forbid top level await) so TypeScript resolves imports and types the modern Node.js way. Also make sure your TypeScript version (both used via CLI, and the one powering VS Code intellisense) is up to date as only recent versions of TypeScript support that mode and appropriately make use of the package.json exports field and such.

jaydenseric commented 2 years ago

I just realise in your screenshot here that you're not specifying the full file name with extension in the import path. You were doing so correctly in the first screenshot here.

wojtekKrol commented 2 years ago

Still nothing image

jaydenseric commented 2 years ago

@wojtekKrol there are several things wrong at once in that screenshot. Firstly, it looks in the bottom left like your TypeScript version is out of date because it's failing to recognise the node16 value. Another thing wrong is you are trying to import something that doesn't exist; use:

import type { FileUpload } from "graphql-upload/processRequest.js";

Another problem you can see in the bottom right is you are attempting to use Node.js to run ESM without using the correct .mjs file extension, as the error message says.

wojtekKrol commented 2 years ago

Okey so let me clarify

In my project I'm using typescript 4.7.2and node 14.18.3 (because `graphql-upload v15.0.2 supports node >14.17.0)

now I've edited package.json added at top level as typescript suggest

  "type": "module",

and still gets this errors: image image image

this is my tsconfig.json

{
  "compilerOptions": {
    "target": "es2020",
    "module": "node16",
    "lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
    "outDir": "./dist",
    "moduleResolution": "node",
    "removeComments": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "baseUrl": ".",
    "sourceMap": true,
    "paths": {
      "@/*": ["src/*"],
      "@test/*": ["test/*"]
    },
    "plugins": [
      {
        "transform": "@zerollup/ts-transform-paths",
        "exclude": ["*"]
      }
    ]
  },
  "exclude": ["node_modules"],
  "include": [
    "./src/**/*.tsx",
    "./src/**/*.ts",
    "./src/**/*.js",
    "./src/**/*.d.ts",
    "./src/**/*.json",
    "./src/**/*.json5",
    "./test/**/*.ts",
    "./src/**/*.csv",
    "./node_modules/graphql-upload/*.js"
  ]
}

Currently because of typescript version I can not even run ttsc -w which is wrapper on tsc because I get errors @jaydenseric

jaydenseric commented 2 years ago

Without looking at the other settings, "moduleResolution": "node" is wrong; it's overriding the behavior of "module": "node16". Try deleting it.

dkruk commented 2 years ago

Have the same issue