Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
Not sure how to Import crypto-js to a test page served from express.js

I'm trying to import crypto-js so I can use any of the crypto-js functions. I can't successfully import it when I serve a static test webpage from Express.js.

I get the error Uncaught SyntaxError: import not found: sha256 in the browser console.

To reproduce with code snippets below:

  1. create directory
  2. npm install express
  3. npm install crypto-js
  4. put the app.js file in the root directory of the project
  5. create a public folder in the root directory of the project
  6. put index.html and index.js files both in the /public directory
  7. open a terminal and go to the project and type node app.js to run it
  8. then go to your browser and go to 127.0.0.1:3000/static/
  9. open the browser console to see the error.

I have tried changing the path of the import statement to import sha256 from 'crypto-js/sha256'; but that just leads to another error.

app.js

const express = require('express');
const app = express();
const port = 3000;
const path = require('path');
app.use('/static' , express.static(path.join(__dirname,'/node_modules')));
app.use('/static', express.static(path.join(__dirname, '/public')));
app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

index.html

<!DOCTYPE html>
<html>
    <head>
        <title> Test Page! </title>
        <script  src="index.js" type="module" ></script>
        
    </head>
    <body>
            <h1>TEST PAGE!</h1>
    </body>
</html>

index.js

import {sha256} from '/static/crypto-js/sha256.js';

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda