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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: path ... is a file when running ng update @angular/material #22919

Closed
1 of 15 tasks
Juarrow opened this issue Jun 8, 2021 · 4 comments
Closed
1 of 15 tasks

Error: path ... is a file when running ng update @angular/material #22919

Juarrow opened this issue Jun 8, 2021 · 4 comments
Assignees
Labels
area: cdk/schematics cdk/schematics is *not* a public API P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@Juarrow
Copy link

Juarrow commented Jun 8, 2021

馃悶 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

I don't know

Description

After updating Angular 11 -> 12

When running the command ng update @angular/material it fails while encountering a reference of a css file in the styleUrls-property of a @component annotation.

馃敩 Minimal Reproduction

馃敟 Exception or Error


[error] Error: Path "/node_modules/@baklavajs/plugin-renderer-vue/dist/styles.css" is a file.
    at HostTree.getDir (C:\projects\subproject-core\subproject-frontend\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:227:19)
    at HostTree.getDir (C:\projects\subproject-core\subproject-frontend\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:235:58)
    at HostTree.getDir (C:\projects\subproject-core\subproject-frontend\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:235:58)
    at DevkitFileSystem._isExistingDirectory (C:\projects\subproject-core\subproject-frontend\node_modules\@angular\cdk\schematics\ng-update\devkit-file-system.js:82:32)
    at DevkitFileSystem.exists (C:\projects\subproject-core\subproject-frontend\node_modules\@angular\cdk\schematics\ng-update\devkit-file-system.js:50:57)
    at Object.host.directoryExists (C:\projects\subproject-core\subproject-frontend\node_modules\@angular\cdk\schematics\update-tool\utils\virtual-host.js:62:52)
    at Object.directoryProbablyExists (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:18294:46)
    at loadNodeModuleFromDirectoryWorker (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:40029:66)
    at loader (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:40131:17)
    at loadModuleFromSpecificNodeModulesDirectory (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:40150:16)
    at loadModuleFromImmediateNodeModulesDirectory (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:40101:58)
    at C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:40091:39
    at Object.forEachAncestorDirectory (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:6390:26)
    at loadModuleFromNearestNodeModulesDirectoryWorker (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:40085:19)
    at loadModuleFromNearestNodeModulesDirectory (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:40077:16)
    at tryResolve (C:\projects\subproject-core\subproject-frontend\node_modules\typescript\lib\typescript.js:39796:34)

馃實 Your Environment


Angular CLI: 11.2.6
Node: 14.15.4
OS: win32 x64

Angular: 
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1102.6 (cli-only)
@angular-devkit/build-angular   < error >
@angular-devkit/core            11.2.6 (cli-only)
@angular-devkit/schematics      11.2.6 (cli-only)
@angular/cli                    11.2.6 (cli-only)
@schematics/angular             11.2.6 (cli-only)
@schematics/update              0.1102.6 (cli-only)
rxjs                            6.6.3 (cli-only)
typescript                      4.2.3 (cli-only)

@crisbeto crisbeto transferred this issue from angular/angular-cli Jun 8, 2021
@crisbeto crisbeto added the needs triage This issue needs to be triaged by the team label Jun 8, 2021
@crisbeto
Copy link
Member

crisbeto commented Jun 8, 2021

@devversion it looks like our schematic code is trying to process something inside the node_modules. Do you what might be causing it?

@crisbeto crisbeto added the area: cdk/schematics cdk/schematics is *not* a public API label Jun 8, 2021
@mmalerba mmalerba added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Jun 14, 2021
@devversion
Copy link
Member

Do you have a snippet showing how the external style is referenced in the styleUrls? Is it just the path as written out in the error, or is the URL different there?

@devversion
Copy link
Member

I've looked more into it. This seems related to b8b3923.

The Angular devkit calls getDir recursively (to walk up the path) if there are no cache entries, and the getDir call will break if it discovers a file and folder named equally. We tried to guard against this for the first parent by calling this._tree.exists(), but this does not capture cases where getDir walks up multiple levels. This can happen if TS tries to guess paths.

Something I find surprising though: Why does TypeScript try to resolve your stylesheet path in styleUrls. Are you using a dynamic import statement or something around that? (e.g. import(<..>, or require)

devversion added a commit to devversion/material2 that referenced this issue Jun 15, 2021
TypeScript resolves modules using a rather complicated module
resolution algorithm. The algorithm tries various paths to
determine a possible entry-point for a module. e.g. it also
respects a containing `package.json` file, or respects the closest
`node_modules` parent directory.

In some situations, TypeScript could end up trying a path where
a parent directory segment resolves to an existent file. e.g.

consider the following directory structure:

```
node_modules/my-pkg/package.json
node_modules/my-pkg/styles.css
```

TypeScript could end up trying a path like:
`node_modules/my-pkg/styles.css/package.json` or
`node_modules/my-pkg/styles.css/a/b/package.json`. This depends on how
the module resolution executes, and how the module is referenced. In the
example above though, TypeScript checks if the files exist. Our update
logic delegates this check to our virtual file system. The virtual file
system currently would throw an error by accident as it walks up the
path and discovers that `styles.css` is not a directory, _but_ a file.

This results in an error as seen in
angular#22919.
devversion added a commit to devversion/material2 that referenced this issue Jun 15, 2021
TypeScript resolves modules using a rather complicated module
resolution algorithm. The algorithm tries various paths to
determine a possible entry-point for a module. e.g. it also
respects a containing `package.json` file, or respects the closest
`node_modules` parent directory.

In some situations, TypeScript could end up trying a path where
a parent directory segment resolves to an existent file. e.g.

consider the following directory structure:

```
node_modules/my-pkg/package.json
node_modules/my-pkg/styles.css
```

TypeScript could end up trying a path like:
`node_modules/my-pkg/styles.css/package.json` or
`node_modules/my-pkg/styles.css/a/b/package.json`. This depends on how
the module resolution executes, and how the module is referenced. In the
example above though, TypeScript checks if the files exist. Our update
logic delegates this check to our virtual file system. The virtual file
system currently would throw an error by accident as it walks up the
path and discovers that `styles.css` is not a directory, _but_ a file.

This results in an error as seen in
angular#22919.

Fixes angular#22919.
devversion added a commit to devversion/material2 that referenced this issue Jun 15, 2021
TypeScript resolves modules using a rather complicated module
resolution algorithm. The algorithm tries various paths to
determine a possible entry-point for a module. e.g. it also
respects a containing `package.json` file, or respects the closest
`node_modules` parent directory.

In some situations, TypeScript could end up trying a path where
a parent directory segment resolves to an existent file. e.g.

consider the following directory structure:

```
node_modules/my-pkg/package.json
node_modules/my-pkg/styles.css
```

TypeScript could end up trying a path like:
`node_modules/my-pkg/styles.css/package.json` or
`node_modules/my-pkg/styles.css/a/b/package.json`. This depends on how
the module resolution executes, and how the module is referenced. In the
example above though, TypeScript checks if the files exist. Our update
logic delegates this check to our virtual file system. The virtual file
system currently would throw an error by accident as it walks up the
path and discovers that `styles.css` is not a directory, _but_ a file.

This results in an error as seen in
angular#22919.

Fixes angular#22919.
devversion added a commit to devversion/material2 that referenced this issue Jun 15, 2021
TypeScript resolves modules using a rather complicated module
resolution algorithm. The algorithm tries various paths to
determine a possible entry-point for a module. e.g. it also
respects a containing `package.json` file, or respects the closest
`node_modules` parent directory.

In some situations, TypeScript could end up trying a path where
a parent directory segment resolves to an existent file. e.g.

consider the following directory structure:

```
node_modules/my-pkg/package.json
node_modules/my-pkg/styles.css
```

TypeScript could end up trying a path like:
`node_modules/my-pkg/styles.css/package.json` or
`node_modules/my-pkg/styles.css/a/b/package.json`. This depends on how
the module resolution executes, and how the module is referenced. In the
example above though, TypeScript checks if the files exist. Our update
logic delegates this check to our virtual file system. The virtual file
system currently would throw an error by accident as it walks up the
path and discovers that `styles.css` is not a directory, _but_ a file.

This results in an error as seen in
angular#22919.

Fixes angular#22919.
wagnermaciel pushed a commit that referenced this issue Jun 16, 2021
TypeScript resolves modules using a rather complicated module
resolution algorithm. The algorithm tries various paths to
determine a possible entry-point for a module. e.g. it also
respects a containing `package.json` file, or respects the closest
`node_modules` parent directory.

In some situations, TypeScript could end up trying a path where
a parent directory segment resolves to an existent file. e.g.

consider the following directory structure:

```
node_modules/my-pkg/package.json
node_modules/my-pkg/styles.css
```

TypeScript could end up trying a path like:
`node_modules/my-pkg/styles.css/package.json` or
`node_modules/my-pkg/styles.css/a/b/package.json`. This depends on how
the module resolution executes, and how the module is referenced. In the
example above though, TypeScript checks if the files exist. Our update
logic delegates this check to our virtual file system. The virtual file
system currently would throw an error by accident as it walks up the
path and discovers that `styles.css` is not a directory, _but_ a file.

This results in an error as seen in
#22919.

Fixes #22919.

(cherry picked from commit 805d3ae)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/schematics cdk/schematics is *not* a public API P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

4 participants