DEV Community

Rafael Lima
Rafael Lima

Posted on • Updated on

Fix path reference

It took me some minutes to realize the cause of the problem. The console showed Uncaught SyntaxError: Unexpected identifier at scripts.js:1. But the thing is nothing was wrong in scripts file. Even the line, 1 where the console was pointing the error to.

Going further inside the scripts file in browser's console, the only message was the error message from a if statement in case the data was not found. But that message was in another file.
After more or less 30 minutes, i found a dumb syntax error from where the scripts.jswas being called.

As i was using the express middleware to watch for static files in the public folder, i suppose the express was reaching to the the folder and expecting a path then, if there was one, of course.

🔧 How it was set up
server.use(express.static("public"))

💬 How file was called
<script src="./scripts.js"></script>

❌ The error
Uncaught SyntaxError: Unexpected identifier

At this point, the framework was trying to access the path this way: folder/public./scripts.js

✅ The solution
<script src="/scripts.js"></script>

💡 How should it be avoided?
Understanding more about file paths and how to use them in Linux

Simply remove the dot from the path that was avoiding express to get to the script file.

💭 Conclusion
When you are new, almost everything seems very complex and it is hard to deconstruct your thoughts to know where and how every piece of code connect with each other, wich prevents you from having a more analytical thinking.


🏗 The project: https://github.com/rafaellimags/gym-manager

Top comments (0)