Open guiaramos opened 3 years ago
i suffer same problem.
this issue happened on versio update to 3.2.5, its working on 3.2.4:
problem: the pr: https://github.com/apollographql/apollo-client/pull/7185 the commit: https://github.com/apollographql/apollo-client/commit/e145a860a10c12fdc4d863379f32e4080597323b at src/utilities/graphql/transform.ts
@guiaramos This appears to be a known issue related to the graphql
package's use of the .mjs
file extension: https://github.com/graphql/graphql-js/issues/1272. Can you try adding mjs
to your moduleFileExtensions
, at the beginning of the list (so it takes precedence over js
)? If that doesn't fix the problem, please put these snippets of code together into a reproduction so that we can investigate further.
In case you're wondering, reverting #7185 is not an option for the reasons I explained in https://github.com/apollographql/apollo-client/pull/7185#pullrequestreview-512013147. Both graphql
v14 and v15 export visit
and BREAK
from the top-level graphql
package, so I don't see anything wrong with the way we're importing those exports within @apollo/client
.
Just to be sure, though, what version of the graphql
package are you using?
@benjamn thanks for your reply. fully understand the point.
Can you try adding mjs to your moduleFileExtensions, at the beginning of the list (so it takes precedence over js)?
causes the following error:
Details:
/Users/guilhermeramos/Desktop/projects.nosync/snuper/web/node_modules/graphql/graphql.mjs:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import isPromise from "./jsutils/isPromise.mjs";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (node_modules/@apollo/client/utilities/utilities.cjs.js:7:15)
Just to be sure, though, what version of the graphql package are you using?
"graphql": "15.4.0",
I will create a reproduction soon and post here
@guiaramos Did you fixed the issue? i get the same error running my tests, which work fine in the version before.
The mentioned workaround
Can you try adding mjs to your moduleFileExtensions, at the beginning of the list (so it takes precedence over js)?
gives me the same SyntaxError
SyntaxError: Cannot use import statement outside a module
@guiaramos Did you fixed the issue? i get the same error running my tests, which work fine in the version before.
The mentioned workaround
Can you try adding mjs to your moduleFileExtensions, at the beginning of the list (so it takes precedence over js)?
gives me the same SyntaxError
SyntaxError: Cannot use import statement outside a module
@zerocewl I was able to fix the issue by just pin the @apollo/client to version 3.2.4:
@apollo/client: "3.2.4"
@guiaramos Obviously pinning the version is not the preferred option ;-)
Did you get a reproduction repo ready?
Let us know if this is still a concern with @apollo/client@latest
- thanks!
This is still happening on @apollo/client@3.3.2
and graphql@15.5.1
only when running tests using jest
. The app and queries otherwise work ok.
@pulkit110 i have the same issue. Have you find a way to fix it?
@paigekim29 I haven't been able to find a solution for this. Until this is resolved on Apollo, we are stuck with pinning to 3.2.4
.
cc @hwillson I believe this is still a concern.
Would someone mind trying things with @apollo/client@beta
to see if this still happens? If so, would you mind firing over a small runnable reproduction? Thanks!
@hwillson Here is a repro.
Longer version: While trying to create a repo, I noticed that it doesn't happen on a brand new project.
After some digging, it seems that I had a mock named graphql.ts
(not at the root, but nested, for example at core/__mocks__
). Just having this file (with empty content) in the filesystem even without any other file accessing this or manually activating this was what was causing this issue. And I confirm that this does not happen on @apollo/client
<= 2.2.4.
I still think this is something that is caused by something that changed on Apollo (or a dependency) because the a custom mock nested inside a project should not interfere with the global graphql
package. At the very least, this should be documented somewhere.
Workaround for now: Check that you don't have any mocks named graphql
(even nested) and rename if there are.
Thanks for the repro @pulkit110. I have a feeling this issue is being caused by graphql.macro
, not Apollo Client. To test this theory try replacing your use of graphql.macro
with direct graphql-tag
calls, using the gql
function exported from @apollo/client
, to see if things then work properly.
Thanks for checking this out @hwillson. I tried without graphql.macro
and have the same error. I have created a repo for the reproduction so that it is easy to check out. Please let me know if you have any other questions.
@hwillson Here is a repro.
Longer version: While trying to create a repo, I noticed that it doesn't happen on a brand new project.
After some digging, it seems that I had a mock named
graphql.ts
(not at the root, but nested, for example atcore/__mocks__
). Just having this file (with empty content) in the filesystem even without any other file accessing this or manually activating this was what was causing this issue. And I confirm that this does not happen on@apollo/client
<= 2.2.4.I still think this is something that is caused by something that changed on Apollo (or a dependency) because the a custom mock nested inside a project should not interfere with the global
graphql
package. At the very least, this should be documented somewhere.Workaround for now: Check that you don't have any mocks named
graphql
(even nested) and rename if there are.
Deleting the mocks folder fixed it for me, thanks
@pulkit110 We had a similar problem with webpack misresolving graphql
to a local graphql.ts
module recently: #8862
Are you using webpack? Do you have preferRelative: true
enabled, by any chance?
Hi @benjamn, thanks for the update. I have tried on the reproduction repository by turning off preferRelative
(even though it should have already been off). This does not fix the failing test.
@hwillson Here is a repro.
Longer version: While trying to create a repo, I noticed that it doesn't happen on a brand new project.
After some digging, it seems that I had a mock named
graphql.ts
(not at the root, but nested, for example atcore/__mocks__
). Just having this file (with empty content) in the filesystem even without any other file accessing this or manually activating this was what was causing this issue. And I confirm that this does not happen on@apollo/client
<= 2.2.4.I still think this is something that is caused by something that changed on Apollo (or a dependency) because the a custom mock nested inside a project should not interfere with the global
graphql
package. At the very least, this should be documented somewhere.Workaround for now: Check that you don't have any mocks named
graphql
(even nested) and rename if there are.
We had a few graphql.js files inside our folders with some our content, after renaming them the problem is gone. Thx @pulkit110
Same exact problem here. Could not find exported members from graphql
package. After renaming a file in our repo from graphql.ts
to _graphql.ts
, the problem is fixed 100%.
Intended outcome:
We are trying to mock the graphql for teting with jest on NextJS
Actual outcome:
We are getting the following error:
How to reproduce the issue:
Our files:
Task.test.tsx
test.tsx
AmIBossDocument
jest.config.js
jest.setup.js
tsconfig.jest.json
Versions
NextJS 9.4.0