Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
La secuencia de comandos externa no funciona en el archivo html, por favor, ¿qué estoy haciendo mal?

Tengo el siguiente archivo game.mjs con el siguiente código

 import Player from './Player.mjs'; import Collectible from './Collectible.mjs'; const socket = io(); const canvas = document.getElementById('game-window'); const context = canvas.getContext('2d'); const load = () => { context.fillStyle = "#000000"; context.fillRect(0, 0, canvas.width, canvas.height); context.font = "30px Comic Sans MS"; context.fillStyle = "red"; context.textAlign = "center"; context.fillText("Coin Race", 100, 30); context.strokeStyle = "yellow"; context.strokeRect(5, 35, canvas.width - 10, canvas.height - 40) } load();

Tengo lo siguiente en el archivo index.html

 <!DOCTYPE html> <html> <head> <title>Secure Real-Time Multiplayer Game</title> <meta name="description" content="An example for the fCC InfoSec Secure Real-Time Multiplayer Game project" /> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" href="../public/style.css" type="text/css" /> <link href="https://fonts.googleapis.com/css?family=Press+Start+2P&display=swap" rel="stylesheet"> <script src="/socket.io/socket.io.js"></script> </head> <body> <header> <h1>Secure Real Time Multiplayer Game</h1> </header> <hr style="margin: 25px" /> <div class="container"> <canvas ref="game" id="game-window" width="640" height="480" > </canvas> </div> </body> <script src="../public/game.mjs" type="module"></script> </html>

El archivo externo no se ejecuta con la etiqueta del script, pero si agrego el código directamente en el archivo html en la etiqueta del script, funciona.

¿Alguien puede decirme qué estoy haciendo mal?

Me doy cuenta de que cuando comento lo siguiente en game.mjs, se ejecuta el script externo

 import Player from './Player.mjs'; import Collectible from './Collectible.mjs'; const socket = io();

Gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Problema encontrado. Cambié app.listen en mi archivo server.js a http.listen y ahora funciona bien. Gracias por su tiempo y ayuda

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!