Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wojtekKrol opened this issue Jun 29, 2022 · 11 comments

Comments

@wojtekKrol
Copy link

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?

@wojtekKrol wojtekKrol changed the title [v15.0.2] Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /.../node_modules/graphql-upload/package.json [v15.0.2] No "exports" main defined in /.../node_modules/graphql-upload/package.json Jun 29, 2022
@jaydenseric
Copy link
Owner

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

@wojtekKrol
Copy link
Author

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

@jaydenseric
Copy link
Owner

jaydenseric commented Jun 29, 2022

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

@wojtekKrol
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

jaydenseric commented Jun 29, 2022

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
Copy link
Author

wojtekKrol commented Jun 29, 2022

Still nothing
image

@jaydenseric
Copy link
Owner

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

@jaydenseric jaydenseric closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2022
@wojtekKrol
Copy link
Author

Okey so let me clarify

In my project I'm using typescript 4.7.2 and 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
Copy link
Owner

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

@dkruk
Copy link

dkruk commented Jul 11, 2022

Have the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants