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

Internal Error: relativeFrom(....../my-app/node_modules/typescript/lib/lib.d.ts): path is not relative #36777

Closed
Hermholtz opened this issue Apr 23, 2020 · 7 comments
Labels
state: confirmed state: has PR type: bug/fix windows Issue related to Microsoft's Windows operating system
Milestone

Comments

@Hermholtz
Copy link

Hermholtz commented Apr 23, 2020

🐞 Angular app does not build or start on Windows

This error occurs when doing the build from a symlinked directory on Windows, when the physical (original) directory is on the different drive letter than the symlink.

The purpose of this symlink is to overcome shortages of disk space on c: drive, but work as if everything is on c: under the user's home directory, as usual.

Is this a regression?

No.

🔬 Minimal Reproduction

Open command prompt as admin (will need to create a symbolic directory link).
d:\test is the directory in which files reside.
c:\testlink is the symlink to the above.

(any_dir)>cd /D d:\
d:\>mkdir test                           <-- directory for the app
d:\>cd /D c:\
c:\>mklink /D c:\testlink d:\test        <-- admin rights required
symbolic link created for c:\testlink <<===>> d:\test
c:\>cd testlink                          <-- enter into the symlink
c:\testlink>npm install -g @angular/cli
c:\testlink>ng new --routing --skip-git --skip-tests --style css my-app
c:\testlink>cd my-app
c:\testlink\my-app>ng build

or the last step:

ng serve

🔥 Exception or Error

Notice that all paths in dump below are pointing to the physical directory d:\test\my-app, whereas the build was launched from c:\testlink\my-app. The difference is in the drive letter.


C:\testlink\my-app>ng build
Compiling @angular/animations : es2015 as esm2015
Error: Error on worker #2: Error: Internal Error: relativeFrom(d:/test/my-app/node_modules/typescript/lib/lib.d.ts): path is not relative
    at Object.relativeFrom (d:\test\my-app\node_modules\@angular\compiler-cli\src\ngtsc\file_system\src\helpers.js:47:19)
    at NodeJSFileSystem.relative (d:\test\my-app\node_modules\@angular\compiler-cli\src\ngtsc\file_system\src\node_js_file_system.js:112:30)
    at Object.relative (d:\test\my-app\node_modules\@angular\compiler-cli\src\ngtsc\file_system\src\helpers.js:97:19)
    at Object.isWithinPackage (d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\analysis\util.js:14:42)
    at d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\analysis\switch_marker_analyzer.js:35:63
    at Array.filter ()
    at SwitchMarkerAnalyzer.analyzeProgram (d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\analysis\switch_marker_analyzer.js:35:18)
    at Transformer.analyzeProgram (d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\packages\transformer.js:126:61)
    at Transformer.transform (d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\packages\transformer.js:75:27)
    at d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\execution\create_compile_function.js:51:42
    at ClusterMaster.onWorkerMessage (d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:168:27)
    at d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:52:95
    at ClusterMaster. (d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:248:57)
    at step (d:\test\my-app\node_modules\tslib\tslib.js:139:27)
    at Object.next (d:\test\my-app\node_modules\tslib\tslib.js:120:57)
    at d:\test\my-app\node_modules\tslib\tslib.js:113:75
    at new Promise ()
    at Object.__awaiter (d:\test\my-app\node_modules\tslib\tslib.js:109:16)
    at EventEmitter. (d:\test\my-app\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:242:32)
    at EventEmitter.emit (events.js:310:20)
An unhandled exception occurred: NGCC failed.
See "C:\Users\user\AppData\Local\Temp\ng-gZ3RKb\angular-errors.log" for further details.

🌍 Your Environment

Angular Version:


Angular CLI: 9.1.3
Node: 12.16.2
OS: win32 x64

Angular: 9.1.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.3
@angular-devkit/build-angular     0.901.3
@angular-devkit/build-optimizer   0.901.3
@angular-devkit/build-webpack     0.901.3
@angular-devkit/core              9.1.3
@angular-devkit/schematics        9.1.3
@ngtools/webpack                  9.1.3
@schematics/angular               9.1.3
@schematics/update                0.901.3
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

Additional info

I think it won't ever happen on Mac and Linux where there's a single filesystem tree.

@Hermholtz
Copy link
Author

Hermholtz commented Apr 23, 2020

Contents of angular-errors.log:


[error] Error: NGCC failed.
    at NgccProcessor.process (d:\test\my-app\node_modules\@ngtools\webpack\src\ngcc_processor.js:76:19)
    at d:\test\my-app\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:579:31
    at SyncHook.eval [as call] (eval at create (d:\test\my-app\node_modules\tapable\lib\HookCodeFactory.js:19:10), :7:1)
    at SyncHook.lazyCompileHook (d:\test\my-app\node_modules\tapable\lib\Hook.js:154:20)
    at Object.webpack [as webpackFactory] (d:\test\my-app\node_modules\webpack\lib\webpack.js:55:30)
    at createWebpack (d:\test\my-app\node_modules\@angular-devkit\build-webpack\src\webpack\index.js:19:36)
    at Object.runWebpack (d:\test\my-app\node_modules\@angular-devkit\build-webpack\src\webpack\index.js:33:12)
    at SwitchMapSubscriber.project (d:\test\my-app\node_modules\@angular-devkit\build-angular\src\browser\index.js:130:32)
    at SwitchMapSubscriber._next (d:\test\my-app\node_modules\@angular-devkit\build-angular\node_modules\rxjs\internal\operators\switchMap.js:49:27)
    at SwitchMapSubscriber.Subscriber.next (d:\test\my-app\node_modules\@angular-devkit\build-angular\node_modules\rxjs\internal\Subscriber.js:66:18)
    at d:\test\my-app\node_modules\@angular-devkit\build-angular\node_modules\rxjs\internal\util\subscribeToPromise.js:7:24

@pkozlowski-opensource pkozlowski-opensource added the area: compiler Issues related to `ngc`, Angular's template compiler label Apr 23, 2020
@ngbot ngbot bot added this to the needsTriage milestone Apr 23, 2020
@Hermholtz
Copy link
Author

I have updated the bug report and the comment below with new info. The bug only occurs in a very specific setup.

@alan-agius4 alan-agius4 added comp: ngcc and removed area: compiler Issues related to `ngc`, Angular's template compiler labels Apr 23, 2020
@efren-cabrera

This comment has been minimized.

@B-apt
Copy link

B-apt commented Jun 5, 2020

I face the same problem (Windows 10):
In my command prompt I'm in path:
"C:\Users\myuser\IdeaProjects\console\console-auth-ui\front"

But "C:\Users\myuser\IdeaProjects" is a symlink (created through mklink) to "D:\Workspaces\IdeaProjects"

Errors when trying to build the project is:

Error: Error on worker #2: Error: Internal Error: relativeFrom(D:/Workspaces/IdeaProjects/console/console-auth-ui/front/node_modules/typescript/lib/lib.d.ts): path is not relative
    at Object.relativeFrom (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\src\ngtsc\file_system\src\helpers.js:47:19)
    at NodeJSFileSystem.relative (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\src\ngtsc\file_system\src\node_js_file_system.js:112:30)
    at CachedFileSystem.relative (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\src\ngtsc\file_system\src\cached_file_system.js:184:34)
    at Object.relative (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\src\ngtsc\file_system\src\helpers.js:97:19)
    at Object.isWithinPackage (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\analysis\util.js:14:42)
    at D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\analysis\switch_marker_analyzer.js:35:63
    at Array.filter (<anonymous>)
    at SwitchMarkerAnalyzer.analyzeProgram (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\analysis\switch_marker_analyzer.js:35:18)
    at Transformer.analyzeProgram (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\packages\transformer.js:126:61)
    at Transformer.transform (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\packages\transformer.js:75:27)
    at ClusterMaster.onWorkerMessage (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:166:27)
    at D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:50:95
    at ClusterMaster.<anonymous> (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:246:57)
    at step (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\tslib\tslib.js:139:27)
    at Object.next (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\tslib\tslib.js:120:57)
    at D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\tslib\tslib.js:113:75
    at new Promise (<anonymous>)
    at Object.__awaiter (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\tslib\tslib.js:109:16)
    at EventEmitter.<anonymous> (D:\Workspaces\IdeaProjects\console\console-auth-ui\front\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:240:32)
    at EventEmitter.emit (events.js:210:5)
An unhandled exception occurred: NGCC failed.

Environment:

14 verbose cwd C:\Users\myuser\IdeaProjects\console\console-auth-ui\front
15 verbose Windows_NT 10.0.17763
16 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\myuser\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "npm-build-prod"
Angular CLI: 9.1.1
Node: 12.12.0
OS: win32 x64

Angular: 9.1.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.1
@angular-devkit/build-angular     0.901.1
@angular-devkit/build-optimizer   0.901.1
@angular-devkit/build-webpack     0.901.1
@angular-devkit/core              9.1.1
@angular-devkit/schematics        9.1.1
@angular/cdk                      9.2.1
@angular/cli                      9.1.1
@ngtools/webpack                  9.1.1
@schematics/angular               9.1.1
@schematics/update                0.901.1
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

Edit:
If I go to "D:\Workspaces\IdeaProjects" with my command prompt and start the build from there, it's working correctly.

@petebacondarwin petebacondarwin added the windows Issue related to Microsoft's Windows operating system label Jun 15, 2020
@petebacondarwin
Copy link
Member

I can reproduce this on my Windows machine. Thanks for the excellent, clear and simple reproduction steps @Hermholtz

@petebacondarwin
Copy link
Member

So here is the problem. In our FileSystem abstraction we have

  relative<T extends PathString>(from: T, to: T): PathSegment {
    return relativeFrom(this.normalize(p.relative(from, to)));
  }

In the withinPackage() function we are calling this to work out if the relative path between filePath and the packagePath indicate that the filePath is "outside" the packagePath.

export function isWithinPackage(packagePath: AbsoluteFsPath, filePath: AbsoluteFsPath): boolean {
  const relativePath = relative(packagePath, filePath);
  return !relativePath.startsWith('..') && !relativePath.startsWith('node_modules/');
}

Unfortunately, in this case the two paths are on different drives (i.e. C: and D:), which means that the "relative path" between the two is "not relative"!!

The problem is that relative() is designed only to work in file-systems that have a single file-tree. We need to have a think about how this can be handled...

petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jul 7, 2020
The `fs.relative()` method assumed that the file-system is a single tree,
which is not the case in Windows, where you can have multiple drives,
e.g. `C:`, `D:` etc.

This commit changes `fs.relative()` so that it no longer forces the result
to be a `PathSegment` and then flows that refactoring through the rest of
the compiler-cli (and ngcc).  The main difference is that in some cases
we needed to check whether the result is "rooted", i.e and AbsoluteFsPath,
rather than a `PathSegment`, before using it.

Fixes angular#36777
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jul 7, 2020
The `fs.relative()` method assumed that the file-system is a single tree,
which is not the case in Windows, where you can have multiple drives,
e.g. `C:`, `D:` etc.

This commit changes `fs.relative()` so that it no longer forces the result
to be a `PathSegment` and then flows that refactoring through the rest of
the compiler-cli (and ngcc).  The main difference is that in some cases
we needed to check whether the result is "rooted", i.e and AbsoluteFsPath,
rather than a `PathSegment`, before using it.

Fixes angular#36777
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jul 8, 2020
The `fs.relative()` method assumed that the file-system is a single tree,
which is not the case in Windows, where you can have multiple drives,
e.g. `C:`, `D:` etc.

This commit changes `fs.relative()` so that it no longer forces the result
to be a `PathSegment` and then flows that refactoring through the rest of
the compiler-cli (and ngcc).  The main difference is that now, in some cases,
we needed to check whether the result is "rooted", i.e an `AbsoluteFsPath`,
rather than a `PathSegment`, before using it.

Fixes angular#36777
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jul 13, 2020
…ngular#37959)

The `fs.relative()` method assumed that the file-system is a single tree,
which is not the case in Windows, where you can have multiple drives,
e.g. `C:`, `D:` etc.

This commit changes `fs.relative()` so that it no longer forces the result
to be a `PathSegment` and then flows that refactoring through the rest of
the compiler-cli (and ngcc).  The main difference is that now, in some cases,
we needed to check whether the result is "rooted", i.e an `AbsoluteFsPath`,
rather than a `PathSegment`, before using it.

Fixes angular#36777

PR Close angular#37959
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jul 13, 2020
The `fs.relative()` method assumed that the file-system is a single tree,
which is not the case in Windows, where you can have multiple drives,
e.g. `C:`, `D:` etc.

This commit changes `fs.relative()` so that it no longer forces the result
to be a `PathSegment` and then flows that refactoring through the rest of
the compiler-cli (and ngcc).  The main difference is that now, in some cases,
we needed to check whether the result is "rooted", i.e an `AbsoluteFsPath`,
rather than a `PathSegment`, before using it.

Fixes angular#36777
petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Jul 13, 2020
The `fs.relative()` method assumed that the file-system is a single tree,
which is not the case in Windows, where you can have multiple drives,
e.g. `C:`, `D:` etc.

This commit changes `fs.relative()` so that it no longer forces the result
to be a `PathSegment` and then flows that refactoring through the rest of
the compiler-cli (and ngcc).  The main difference is that now, in some cases,
we needed to check whether the result is "rooted", i.e an `AbsoluteFsPath`,
rather than a `PathSegment`, before using it.

Fixes angular#36777
AndrewKushnir pushed a commit that referenced this issue Jul 15, 2020
…38030)

The `fs.relative()` method assumed that the file-system is a single tree,
which is not the case in Windows, where you can have multiple drives,
e.g. `C:`, `D:` etc.

This commit changes `fs.relative()` so that it no longer forces the result
to be a `PathSegment` and then flows that refactoring through the rest of
the compiler-cli (and ngcc).  The main difference is that now, in some cases,
we needed to check whether the result is "rooted", i.e an `AbsoluteFsPath`,
rather than a `PathSegment`, before using it.

Fixes #36777

PR Close #38030
@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 Aug 13, 2020
profanis pushed a commit to profanis/angular that referenced this issue Sep 5, 2020
…ngular#37959)

The `fs.relative()` method assumed that the file-system is a single tree,
which is not the case in Windows, where you can have multiple drives,
e.g. `C:`, `D:` etc.

This commit changes `fs.relative()` so that it no longer forces the result
to be a `PathSegment` and then flows that refactoring through the rest of
the compiler-cli (and ngcc).  The main difference is that now, in some cases,
we needed to check whether the result is "rooted", i.e an `AbsoluteFsPath`,
rather than a `PathSegment`, before using it.

Fixes angular#36777

PR Close angular#37959
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
state: confirmed state: has PR type: bug/fix windows Issue related to Microsoft's Windows operating system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants