Unable to open 'filename': File not found (file:<wrong file path>/filename)

故事扮演 提交于 2020-01-16 18:51:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!