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

LoadPluginError: Could not load plugin #23435

Closed
2 of 4 tasks
decline opened this issue May 16, 2024 · 9 comments
Closed
2 of 4 tasks

LoadPluginError: Could not load plugin #23435

decline opened this issue May 16, 2024 · 9 comments
Assignees
Labels
scope: core core nx functionality type: bug

Comments

@decline
Copy link

decline commented May 16, 2024

Current Behavior

When using the libraryGenerator() method from @nx/angular/generators inside a (Jest) test, it will fail.

Example:

import { libraryGenerator } from "@nx/angular/generators";
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree } from '@nx/devkit';

describe('my-generator generator', () => {
  let tree: Tree;

  beforeEach(() => {
    tree = createTreeWithEmptyWorkspace();
  });

  it('should run successfully', async () => {
    // this will fail:
    const result =   await libraryGenerator(tree, {
      name: 'test',
      directory: '',
    });

    expect(result).toBeDefined();
  });
});

The test will fail with the following error message:

LoadPluginError: Could not load plugin /app/node_modules/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json

Important:

This error only happens on Linux operating system. The same test passes on a MacOS operating system.

Expected Behavior

The test should run successfully on every operating system.

GitHub Repo

https://github.com/decline/nx-plugin-issue

Steps to Reproduce

  1. Checkout the repository
  2. Run docker compose up

Info:

Starting the docker container will execute the nx run my-plugin:test command which will fail the test. If you run the nx run my-plugin:test command on a MacOS system, it will pass!

Nx Report

NX   Report complete - copy this into the issue template

Node   : 20.10.0
OS     : linux-arm64
npm    : 10.2.3

nx                 : 19.0.4
@nx/js             : 19.0.4
@nx/jest           : 19.0.4
@nx/linter         : 19.0.4
@nx/eslint         : 19.0.4
@nx/workspace      : 19.0.4
@nx/angular        : 19.0.4
@nx/devkit         : 19.0.4
@nx/eslint-plugin  : 19.0.4
@nx/plugin         : 19.0.4
@nrwl/tao          : 19.0.4
@nx/web            : 19.0.4
@nx/webpack        : 19.0.4
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
---------------------------------------
Local workspace plugins:
         @plugin-issue/my-plugin

Failure Logs

LoadPluginError: Could not load plugin /app/node_modules/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json

  12 |   it('should run successfully', async () => {
  13 |     // this will fail:
> 14 |     const result =   await libraryGenerator(tree, {
     |                      ^
  15 |       name: 'test',
  16 |       directory: '',
  17 |     });

  at loadNxPluginAsync (../node_modules/nx/src/project-graph/plugins/loader.js:207:15)
  at loadNxPlugin (../node_modules/nx/src/project-graph/plugins/loader.js:180:9)
  at loadNxPlugins (../node_modules/nx/src/project-graph/plugins/internal-api.js:49:48)
  at async buildProjectGraphAndSourceMapsWithoutDaemon (../node_modules/nx/src/project-graph/project-graph.js:75:32)
  at async createProjectGraphAndSourceMapsAsync (../node_modules/nx/src/project-graph/project-graph.js:202:25)
  at async createProjectGraphAsync (../node_modules/nx/src/project-graph/project-graph.js:191:39)
  at async initEsLint (../node_modules/@nx/eslint/src/generators/init/init.js:41:19)
  at async lintInitGenerator (../node_modules/@nx/eslint/src/generators/init/init.js:80:12)
  at async lintProjectGeneratorInternal (../node_modules/@nx/eslint/src/generators/lint-project/lint-project.js:25:22)
  at async addLintingGenerator (../node_modules/@nx/angular/src/generators/add-linting/add-linting.js:14:22)
  at async addLinting (../node_modules/@nx/angular/src/generators/library/library.js:123:5)
  at async libraryGeneratorInternal (../node_modules/@nx/angular/src/generators/library/library.js:69:5)
  at async libraryGenerator (../node_modules/@nx/angular/src/generators/library/library.js:25:12)
  at async Object.<anonymous> (src/generators/my-generator/generator.spec.ts:14:22)
Cause:
TypeError: performance.mark is not a function

  12 |   it('should run successfully', async () => {
  13 |     // this will fail:
> 14 |     const result =   await libraryGenerator(tree, {
     |                      ^
  15 |       name: 'test',
  16 |       directory: '',
  17 |     });

  at loadNxPluginAsync (../node_modules/nx/src/project-graph/plugins/loader.js:198:21)
  at loadNxPlugin (../node_modules/nx/src/project-graph/plugins/loader.js:180:9)
  at loadNxPlugins (../node_modules/nx/src/project-graph/plugins/internal-api.js:49:48)
  at async buildProjectGraphAndSourceMapsWithoutDaemon (../node_modules/nx/src/project-graph/project-graph.js:75:32)
  at async createProjectGraphAndSourceMapsAsync (../node_modules/nx/src/project-graph/project-graph.js:202:25)
  at async createProjectGraphAsync (../node_modules/nx/src/project-graph/project-graph.js:191:39)
  at async initEsLint (../node_modules/@nx/eslint/src/generators/init/init.js:41:19)
  at async lintInitGenerator (../node_modules/@nx/eslint/src/generators/init/init.js:80:12)
  at async lintProjectGeneratorInternal (../node_modules/@nx/eslint/src/generators/lint-project/lint-project.js:25:22)
  at async addLintingGenerator (../node_modules/@nx/angular/src/generators/add-linting/add-linting.js:14:22)
  at async addLinting (../node_modules/@nx/angular/src/generators/library/library.js:123:5)
  at async libraryGeneratorInternal (../node_modules/@nx/angular/src/generators/library/library.js:69:5)
  at async libraryGenerator (../node_modules/@nx/angular/src/generators/library/library.js:25:12)
  at async Object.<anonymous> (src/generators/my-generator/generator.spec.ts:14:22)

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label May 16, 2024
@digitalhank
Copy link

experiencing the same but with the applicationGenerator from '@nx/next' on v18.3.4

@pedroyan
Copy link

I'm experiencing the same problem. Tests work on MacOS but not on our Linux CI.

It happens when I call the libraryGenerator function from @nx/nest@18.3.4 on a Jest test

@SuneRadich

This comment was marked as off-topic.

@SuneRadich

This comment was marked as off-topic.

@dasco144
Copy link
Contributor

dasco144 commented May 28, 2024

I'm having the same issue when wrapping the service schematic from @schematics/angular, and executing that.

Although, when running locally (MacOS) I get this error

ReferenceError: TextDecoder is not defined

      18 |
      19 |   const serviceGenerator = wrapAngularDevkitSchematic('@schematics/angular', 'service');
    > 20 |   await serviceGenerator(tree, serviceOptions);
         |   ^
      21 |

      at Object.<anonymous> (../../node_modules/@angular-devkit/schematics/src/rules/template.js:33:17)
      at Object.<anonymous> (../../node_modules/@angular-devkit/schematics/src/index.js:56:14)
      at Object.<anonymous> (../../node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:16:15)
      at Object.<anonymous> (../../node_modules/@angular-devkit/schematics/tools/index.js:27:14)
      at createWorkflow (../../node_modules/nx/src/adapter/ngcli-adapter.js:165:26)
      at ../../node_modules/nx/src/adapter/ngcli-adapter.js:697:26
      at serviceGenerator (src/generators/service/generator.ts:20:3)
      at Object.<anonymous> (src/generators/service/generator.spec.ts:34:5)

but on CI I get the same as OP.

@sonikasharma1403
Copy link
Contributor

facing the same issue, but only in the TeamCity environment.

@sonikasharma1403
Copy link
Contributor

@AgentEnder , any update on this?

@hunhavoc
Copy link

hunhavoc commented Jun 6, 2024

Having the same issue. Tests run well on local Mac, but does not work on Linux env in CI.

@AgentEnder
Copy link
Member

Hi there 👋 - so this is a bit more complex than one may imagine. Most typically getting this error during a unit test is a result of a test doing something that is causing the project graph to be created. You'll need to mock the project graph during these tests, and while that sounds rough its also going to give you much more accurate and repeatable tests.

Without mocking the graph, the tests will be running generators which create the project graph of the current Nx workspace and make some decisions about that. That's almost always not really what you want. We just recently fixed that behavior on the Nx repo.

This suddenly became a problem for some folks because several of our published generators do rely on the graph now.

You can see how we are mocking this in our unit test setup: https://github.com/nrwl/nx/blob/master/scripts/unit-test-setup.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: core core nx functionality type: bug
Projects
None yet
Development

No branches or pull requests

9 participants