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

findOriginalKeys is not a function or its return value is not iterable #16825

Closed
yharaskrik opened this issue May 5, 2023 · 15 comments · Fixed by #16886
Closed

findOriginalKeys is not a function or its return value is not iterable #16825

yharaskrik opened this issue May 5, 2023 · 15 comments · Fixed by #16886
Assignees
Labels

Comments

@yharaskrik
Copy link
Contributor

Current Behavior

Generating a lockfile fails

App builds correctly just the lockfile fails to generate

Expected Behavior

Should generate a lockfile correctly.

GitHub Repo

No response

Steps to Reproduce

Generate a nest app and try and use the generate package json flag to create a pruned lockfile.

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 18.16.0
   OS     : darwin arm64
   yarn   : 1.22.17
   Hasher : Native
   
   nx                 : 16.1.0
   @nx/js             : 16.1.0
   @nx/jest           : 16.1.0
   @nx/linter         : 16.1.0
   @nx/workspace      : 16.1.0
   @nx/angular        : 16.1.0
   @nx/cypress        : 16.1.0
   @nx/devkit         : 16.1.0
   @nx/eslint-plugin  : 16.1.0
   @nx/express        : 16.1.0
   @nx/nest           : 16.1.0
   @nx/node           : 16.1.0
   @nx/plugin         : 16.1.0
   @nx/storybook      : 16.1.0
   @nrwl/tao          : 16.1.0
   @nx/webpack        : 16.1.0
   nx-cloud           : 16.0.5
   typescript         : 5.0.4


### Failure Logs

```shell
>  NX   An error occured while creating pruned lockfile

   Please open an issue at `https://github.com/nrwl/nx/issues/new?template=1-bug.yml` and provide a reproduction.
   To prevent the build from breaking we are returning the root lock file.
   
Original error: findOriginalKeys is not a function or its return value is not iterable


   TypeError: findOriginalKeys is not a function or its return value is not iterable
    at /Users/jaybell/WebstormProjects/shinkansen/node_modules/nx/src/plugins/js/lock-file/yarn-parser.js:190:41
    at Array.forEach (<anonymous>)
    at mapSnapshots (/Users/jaybell/WebstormProjects/shinkansen/node_modules/nx/src/plugins/js/lock-file/yarn-parser.js:189:26)
    at stringifyYarnLockfile (/Users/jaybell/WebstormProjects/shinkansen/node_modules/nx/src/plugins/js/lock-file/yarn-parser.js:131:23)
    at createLockFile (/Users/jaybell/WebstormProjects/shinkansen/node_modules/nx/src/plugins/js/lock-file/lock-file.js:132:60)
    at /Users/jaybell/WebstormProjects/shinkansen/node_modules/@nx/webpack/src/plugins/generate-package-json-plugin.js:42:124
    at fn (/Users/jaybell/WebstormProjects/shinkansen/node_modules/@nx/webpack/node_modules/webpack/lib/Compilation.js:478:10)
    at _next0 (eval at create (/Users/jaybell/WebstormProjects/shinkansen/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:21:1)
    at eval (eval at create (/Users/jaybell/WebstormProjects/shinkansen/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:34:1)
    at eval (eval at create (/Users/jaybell/WebstormProjects/shinkansen/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)


### Operating System

- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)

### Additional Information

_No response_
@AgentEnder AgentEnder added the scope: core core nx functionality label May 5, 2023
@meeroslav meeroslav self-assigned this May 5, 2023
@meeroslav
Copy link
Contributor

Thank you @yharaskrik for reporting this.

Can you provide a test repo where I can get this error. I tried generating workspace with nest locally, but I could not get the error (the version I used was 16.1.1 but afaik nothing in this patch could be influencing lock file parsing).

Screenshot 2023-05-08 at 13 22 11

@meeroslav
Copy link
Contributor

Just to be sure I generated one repo with yarn as well. Same result:
Screenshot 2023-05-08 at 13 28 00

@yharaskrik
Copy link
Contributor Author

Hmm ya the patch may have affected it I don't think I tried after updating to 16.1.1. will get back to you!

@yharaskrik
Copy link
Contributor Author

Hmm ya still happening for me on 16.1.1, will see if I can create a repro.

@yharaskrik
Copy link
Contributor Author

Haven't been able to repro it yet but I have some additional info. Reading the findOriginalKeys function the package that is failing wrap-ansi never hits this condition

// standard package
        if (snapshot.version === node.data.version) {
            return [keys, snapshot];
        }

There is no snapshot with the same version as the Node being checked (7.0.0)

@yharaskrik
Copy link
Contributor Author

Miro I dm'd you out lockfile. Not sure if its helpful or not.

@kjetilhp
Copy link

kjetilhp commented May 9, 2023

reproduction to generate error: (from #16875)

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

import { http } from '@google-cloud/functions-framework';

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';

import express from 'express';
import { ExpressAdapter } from '@nestjs/platform-express';
const NestServer: express.Express = express();

const environment = {
  dev: !!process.env.DEV,
};

export const createNestServer = async (expressInstance) => {
  const app = await NestFactory.create(
    AppModule,
    new ExpressAdapter(expressInstance)
  );
  const globalPrefix = 'api';
  app.setGlobalPrefix(globalPrefix);
  app.enableCors();
  return app.init();
};

createNestServer(NestServer)
  .then((v) => {
    console.log('Environment', environment);
    if (!environment.dev) {
      Logger.log('🚀 Starting production server...');
    } else {
      Logger.log(
        `🚀 Starting development server on http://localhost:${
          process.env.PORT || 3333
        }`
      );
      v.listen(process.env.PORT || 3333);
    }
  })
  .catch((err) => Logger.error('Nest broken', err));

http('api', NestServer);

package.json generated

{
  "name": "api",
  "version": "0.0.1",
  "dependencies": {
    "@google-cloud/functions-framework": "3.2.0",
    "@nestjs/common": "9.4.0",
    "@nestjs/core": "9.4.0",
    "@nestjs/platform-express": "9.4.0",
    "express": "4.18.2",
    "firebase-admin": "11.8.0",
    "firebase-functions": "4.4.0",
    "reflect-metadata": "0.1.13",
    "rxjs": "7.8.1",
    "tslib": "2.5.0"
  },
  "main": "main.js"
}

nx-report:

>  NX   Report complete - copy this into the issue template

   Node   : 16.15.1
   OS     : darwin arm64
   yarn   : 1.22.19
   Hasher : Native
   
   nx (global)        : 16.0.0
   nx                 : 16.1.3
   @nx/js             : 16.1.3
   @nx/jest           : 16.1.3
   @nx/linter         : 16.1.3
   @nx/workspace      : 16.1.3
   @nx/angular        : 16.1.3
   @nx/cypress        : 16.1.3
   @nx/devkit         : 16.1.3
   @nrwl/devkit       : 15.7.0
   @nx/esbuild        : 16.1.3
   @nx/eslint-plugin  : 16.1.3
   @nx/nest           : 16.1.3
   @nx/node           : 16.1.3
   @nx/plugin         : 16.1.3
   @nx/storybook      : 16.1.3
   @nrwl/tao          : 16.1.3
   @nx/web            : 16.1.3
   @nx/webpack        : 16.1.3
   nx-cloud           : 16.0.5
   typescript         : 5.0.4
   ---------------------------------------
   Community plugins:
   @nx-extend/gcp-cloud-run : 3.4.5
   @nxext/svelte            : 15.7.0
   @nxtensions/astro        : 3.5.0
   @taiga-ui/cdk            : 3.26.0
   @taiga-ui/core           : 3.26.0
   ngfire                   : 0.0.52
   ---------------------------------------
   The following packages should match the installed version of nx
     - @nrwl/[email protected]
   
   To fix this, run `nx migrate [email protected]`

@meeroslav
Copy link
Contributor

Thank you @yharaskrik, I found the issue thanks to your lock-file.

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
  version "7.0.0"
  resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
  integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
  dependencies:
    ansi-styles "^4.0.0"
    string-width "^4.1.0"
    strip-ansi "^6.0.0"

The second key gets ignored. I will try to create a fix as soon as possible.

@yharaskrik
Copy link
Contributor Author

Thank you @yharaskrik, I found the issue thanks to your lock-file.

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
  version "7.0.0"
  resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
  integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
  dependencies:
    ansi-styles "^4.0.0"
    string-width "^4.1.0"
    strip-ansi "^6.0.0"

The second key gets ignored. I will try to create a fix as soon as possible.

Amazing thank you!

@greaterweb
Copy link

My team is experiencing this bug as well, is there any sort of temporary workaround that can be done in the short term?

@yharaskrik
Copy link
Contributor Author

My team is experiencing this bug as well, is there any sort of temporary workaround that can be done in the short term?

Would also love to know if there is a workaround for this for the time being.

@yharaskrik
Copy link
Contributor Author

Maybe have found a workaround. Not sure what the unintended side effects are but if you use yarn you can add this to your resolutions in package.json
"**/wrap-ansi-cjs": "npm:wrap-ansi"

This is the diff that is produced from that in the lock file.
image

@meeroslav
Copy link
Contributor

Your new lock file on the right incorrectly maps v7 to v8.1.0. It could work, but it could also break horribly.
I'm hoping to have this potentially patched today.

cc @FrozenPandaz

@yharaskrik
Copy link
Contributor Author

Your new lock file on the right incorrectly maps v7 to v8.1.0. It could work, but it could also break horribly.
I'm hoping to have this potentially patched today.

cc @FrozenPandaz

Haha figured so. I think it's a dev dependency from what I can't tell and out CI is entirely green 🤷‍♂️ but it would be great to have it patched lll be on the lookout!

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants