问题
I have inherited a project from another developer, and it has an odd quirk I don't understand. It'is an Angular project.
When I load the index.html file, and I ctrl+click on a file, I get error:
Unable to open 'filename': File not found. error.
This doesn't make much sense to me because the path to index.html
is correctly relative to the destination file.
My index.html file is in:
C:\FrontEnd\login-component\app\index.html
My app.js files is in:
C:\FrontEnd\login-component\app\js\app.js
And the link to it in the index.html file is:
script src="js/app.js"
However, the error that pops up says that it can't find app.js file here:
C:\FrontEnd\login-component\js\app.js
which is true, because it's missing the "app" part of the path.
Trying to find out what the problem is, I've tried to delete my .vscode
directory and disabled my C# plugin, but neither seemed to have any effect.
What's stranger is it only seems to be some projects that exhibit this behavior. Does anyone have any suggestions on what could be causing this odd behavior, and how to fix it?
Thanks
回答1:
Okay, I kept looking around and I figured this out.
This has nothing to do with a VSCode setting, as I had thought.
In the index.html file, there was this line:
<base href="/">
With that line in the file, it threw off the relative location for all the files. Commenting it out, the links now work, with no apparent issues with the application running at all.
来源:https://stackoverflow.com/questions/50009329/unable-to-open-filename-file-not-found-filewrong-file-path-filename