0

When i want to put js file i get this error

GET http://localhost:3000/src/app.js net::ERR_ABORTED 404 (Not Found)

HTML

 <!DOCTYPE html>
    <html>
      <head>
        <title>Pug with Java</title>
      </head>
      <body>
        <script src="src/app.js"></script>
      </body>
    </html>

Structure of the project

project structure

AndreiN
  • 47
  • 8

3 Answers3

1

You need to build your app. If you open package.json you will see scripts to build the app.

Build it and include the js from build folder. If your index.html and js file is in same location you dont need to src/ in script src.

Most probably app.js will be changed to main.js after build. Check it in build folder.

Build command will be something like

npm run prod

or

npm run prod-en

Once you do a build you will not have the src folder.

kiranvj
  • 32,342
  • 7
  • 71
  • 76
  • I don't know to build a app,i just get it the pug from github and i wanted to add JS – AndreiN Oct 17 '20 at 16:44
  • I just changed in index.js and now error say index.js:1 Failed to load resource: the server responded with a status of 404 (Not Found) – AndreiN Oct 17 '20 at 16:47
  • and btw the index html is in tmp because i use PUG – AndreiN Oct 17 '20 at 16:48
  • Did you check the `installation` and `usage` docs https://github.com/marianzburlea/pug-starter#installation After that you need to build the app – kiranvj Oct 18 '20 at 02:12
  • i used npm run prod and create me a folder with index.html but still doesn't work – AndreiN Oct 18 '20 at 08:57
  • What all files do you have in the build folder, what is the content of index.html. Can you please update these in your question? – kiranvj Oct 18 '20 at 16:10
  • I fixed that i make it a clone clean from github and make a src/asset/js folder and put the js there and now he see my js. – AndreiN Oct 19 '20 at 11:17
0

In which file is your HTML? If it's in index.pug you should try <script src="app.js"></script> as it's in the same folder.

Tom
  • 387
  • 2
  • 12
0

if you use express.js ,try this , add this code app.use(express.static(path.join(__dirname, ""))); into your app.js to identify the exacly path. to your file.js