首页 > 解决方案 > 为什么我得到一个错误,即找不到 app.js 文件?

问题描述

在这里,这是我的文件夹结构:

 ReactCourse      // It is the root directory
    public        // public is the subfolder in ReactCourse
      index.html  // It is the html file where I linked the js file into html page
    app.js        // It is the app.js file 

这是 index.html 文件:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>React App</title>
</head>
<body class="root">
    <h1>I am header</h1>
    <script src="../app.js" type="text/javascript" ></script> // Here is the script tag
</body>
</html>
 

// 但不幸的是,我得到了一个错误,即在控制台找不到文件。

// 当我将 app.js 文件放入公共文件夹时它工作正常

标签: javascripthtml

解决方案


根据您的文件结构,您的 app.js 文件不在脚本文件夹中。

<script src="---------> ../scripts/app.js <--------" type="text/javascript" ></script> // Here is the script tag

您可能应该使用此路径:

<script src="../app.js" type="text/javascript" ></script> // Here is the script tag


推荐阅读