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

Barrel file missing? Importing @nx/angular/src/utils results in "Cannot find module" error #22588

Closed
1 of 4 tasks
timtos opened this issue Mar 30, 2024 · 3 comments · Fixed by #22609
Closed
1 of 4 tasks
Assignees
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@timtos
Copy link

timtos commented Mar 30, 2024

Current Behavior

Writing a custom nx generator I am trying to import the angular utility addProviderToComponent:

import { addProviderToComponent } from '@nx/angular/src/utils';

Unfortunately, I am getting an error:

Cannot find module '@nx/angular/src/utils' or its corresponding type declarations.ts(2307)

The generator is running happily but the build throws an error.

Please also have a look at the "Additional Information" provided at the bottom.

Expected Behavior

There should be no error and it should be easy to use this helper function.

Steps to Reproduce

Try to use addProviderToComponent within a generator:

const componentPath = 'apps/my-app/src/app/app.component.ts';
const text = tree.read(componentPath);
const sourceX = ts.createSourceFile(componentPath, text.toString(), ts.ScriptTarget.Latest, true);
addProviderToComponent(tree, sourceX, componentPath, 'MyProvider');

Nx Report (custom)

Cannot run the nx report due to an invalid token in my path:
Error: Cannot find module 'C:\Users\T├╝m...

But I am using version:

"nx": "~18.0.7",
"@nx/angular": "~18.0.7",
"@nx/cypress": "~18.0.7",
"@nx/eslint": "~18.0.7",
"@nx/eslint-plugin": "~18.0.7",
"@nx/devkit": "~18.0.7",
"@nx/js": "~18.0.7",
"@nx/plugin": "~18.0.7",
"@nx/storybook": "~18.0.7",
"@nx/web": "~18.0.7",
"@nx/workspace": "~18.0.7",

Operating System

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

Additional Information

In the folder @nx\angular\src\utils I see the file public-api.d.ts with the following content:

export { isStandalone, addImportToComponent, addImportToDirective, addImportToPipe, addImportToModule, addProviderToBootstrapApplication, addProviderToAppConfig, addProviderToComponent, addProviderToModule, } from './nx-devkit/ast-utils';
export { addRoute, addProviderToRoute } from './nx-devkit/route-utils';

If I place an index.ts file in the same location with the same content, everything works as expected.

Is there an index.ts file missing?
Is there another way to import this functionality?

@timtos timtos changed the title Importing @nx/angular/src/utils results in "Cannot find module" error Barrel file missing? Importing @nx/angular/src/utils results in "Cannot find module" error Mar 30, 2024
@timtos
Copy link
Author

timtos commented Mar 30, 2024

A related change was introduced with the 3895696 and it all started here: #15669. Any idea @Coly010?

@Jad31
Copy link

Jad31 commented Apr 1, 2024

Hi, I have the same issue trying to use the addRoute function. I'm on Ubuntu 22.04.4 LTS.

@leosvelperez leosvelperez added the scope: angular Issues related to Angular support in Nx label Apr 2, 2024
@leosvelperez leosvelperez self-assigned this Apr 2, 2024
Copy link

github-actions bot commented May 3, 2024

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 May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants