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

269
Views
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
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!