awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
917 stars 265 forks source link

aws-appsync peerDependencies graphql syntax error #699

Closed sdfrasier closed 2 years ago

sdfrasier commented 2 years ago

Do you want to request a feature or report a bug? BUG

What is the current behavior? aws-appsync v4.1.4 has a syntax error in package.json. I believe this was introduced here: https://github.com/awslabs/aws-mobile-appsync-sdk-js/pull/676

"peerDependencies": {
  "graphql": "0.13.0 | 14.x | 15.x"
}

This causes the following error after running npm ls -prod -json -depth=1: (In this example I'm using graphql 15.8.0 as a dependency)

"graphql": {
  "version": "15.8.0",
  "invalid": "\"0.13.0 | 14.x | 15.x\" from node_modules/aws-appsync",
  "problems": [
    "invalid: graphql@15.8.0 ..."
  ]
},
...
npm ERR! code ELSPROBLEMS
npm ERR! invalid: graphql@15.8.0 ...
{
  "error": {
    "code": "ELSPROBLEMS",
    "summary": "invalid: ...",
    "detail": ""
  }
}

In my case, this is causing serverless-webpack to fail (related to https://github.com/serverless-heaven/serverless-webpack/issues/781)

How to fix The correct way to specify multiple versions is || (see https://github.com/npm/node-semver#versions)

"peerDependencies": {
  "graphql": "0.13.0 || 14.x || 15.x"
}
fcastaneda9725 commented 2 years ago

We had two errors, the first one is:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: investingCreateUser@2.0.0
npm ERR! Found: graphql@14.7.0
npm ERR! node_modules/graphql
npm ERR!   graphql@"^14.7.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer graphql@"0.13.0 | 14.x | 15.x" from aws-appsync@4.1.4
npm ERR! node_modules/aws-appsync
npm ERR!   aws-appsync@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/omarabaroa/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/omarabaroa/.npm/_logs/2022-01-14T21_21_40_899Z-debug.log

Then needed to install cmake because of the following error:

npm ERR! code 1
npm ERR! path /Users/xxxxxxx/app/amplify/backend/function/investingCreateUser/src/node_modules/aws-crt
npm ERR! command failed
npm ERR! command sh -c node ./scripts/install.js
npm ERR! info TOOL Using Unix Makefiles generator.
npm ERR! info TOOL Building only the install target, as specified from the command line.
npm ERR! ERR! OMG CMake executable is not found. Please use your system's package manager to install it, or you can get installers from there: http://cmake.org.
npm ERR! /Users/xxxxxx/app/amplify/backend/function/investingCreateUser/src/node_modules/cmake-js/lib/cMake.js:117
npm ERR!         throw new Error("CMake executable is not found. Please use your system's package manager to install it, or you can get installers from there: http://cmake.org.");
npm ERR!               ^
npm ERR! 
npm ERR! Error: CMake executable is not found. Please use your system's package manager to install it, or you can get installers from there: http://cmake.org.
npm ERR!     at CMake.verifyIfAvailable (/Users/xxxxx/app/amplify/backend/function/investingCreateUser/src/node_modules/cmake-js/lib/cMake.js:117:15)
npm ERR!     at CMake.build (/Users/xxxxx/app/amplify/backend/function/investingCreateUser/src/node_modules/cmake-js/lib/cMake.js:287:10)
npm ERR!     at BuildSystem._invokeCMake (/Users/xxxxxx/app/amplify/backend/function/investingCreateUser/src/node_modules/cmake-js/lib/buildSystem.js:70:40)
npm ERR!     at async buildFromRemoteSource (/Users/xxxxx/app/amplify/backend/function/investingCreateUser/src/node_modules/aws-crt/scripts/build.js:148:5)

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxxxx/.npm/_logs/2022-01-14T21_24_08_610Z-debug.log

And run again npm install --force

diegoconcha commented 2 years ago

To clarify @fcastaneda9725 ran into the graphql peer dependency issue @sdfrasier mentioned above. We've run into a similar peerDependency problem before and have gotten around it via npm i --force but running that then brought up the cmake issue that he resolved by installing cmake via homebrew locally on his machine.

After installing cmake, npm i --force worked and our lambda was able to run.

Mr0cket commented 2 years ago

@sammartinez Any updates regarding this? Your packages have been using peerDependency syntax which is incompatible with semver for a long time... rather annoying to fix every time packages are re-installed.

using --legacy-peer-deps is not an acceptable solution.

Considering how trivial the fix is, why is it taking so long?

mattiLeBlanc commented 2 years ago

Hi, this issue seems to still be prevalent in version 4.1.5. I am getting the same issue:

npm i
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: aws-appsync@4.1.5
npm WARN Found: graphql@undefined
npm WARN node_modules/graphql
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer graphql@"0.13.0 | 14.x | 15.x" from aws-appsync@4.1.5
npm WARN node_modules/aws-appsync

I am still seeing

"peerDependencies": {
    "graphql": "0.13.0 | 14.x | 15.x"
  }

in the aws-appsync package file. If this is not allowed, why is this not quickly fixed? I had to downgrade to a very old version to be able to use appsync in my Lambda

"dependencies": {
        "aws-appsync": "3.0.2",
        "cross-fetch": "^3.1.5",
        "graphql": "^14.6.0",
        "graphql-tag": "2.10.3",
        "redux": "^3.7.2"
    }
blazinaj commented 2 years ago

I see this fix was added through a PR above, when/how can I access the package version that includes it?

Mr0cket commented 2 years ago

It appears the patch was added to the apollov2 branch.

You can confirm this by checking the package.json here: https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/apollov2/packages/aws-appsync/package.json

this branch is set to v4.1.6

using npm view aws-appsync you can see the latest tag is also v4.1.6. To me this means that it should be included in the latest release. otherwise you can include the apollov2 dist tag when using npm install. e.g: npm i aws-appsync@apollov2

Mr0cket commented 2 years ago

Uhh wait... looks like the patch hasn't been released yet...

blazinaj commented 2 years ago

Hello, any update on this? I'm really confused how this hasn't affected many more people. It breaks every single one of our build pipelines. Any idea on the aws-appsync version that I can roll back to that's before this "little" bug got introduced?

lukebenimble commented 2 years ago

@blazinaj We're stuck on 4.1.2 and that still seems to work for us, but I'd imagine it is effecting a lot of people and they're just sticking on the last working version for the time being.

dpilch commented 2 years ago

Sorry for the delay, the fix should be released in 4.1.7 now.