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

223
Views
JS cannot import npm module

I can't import npm module using for example import fs from 'fs'; in my main.js file that linked with index.html. Script tag that connect JS file has attribute type="module". Error in console of browser throws error: Uncaught TypeError: Failed to resolve module specifier "fs". Relative references must start with either "/", "./", or "../".. BUT npm modules must be connected by pointing only module name, without path and I already did that in another project and it worked correctly.

Then I tried to point relative path to fs module. But node_modules doesn't have folder 'fs'. Instead it contains several folders with 'fs' in start of each folder name.

At that moment I was completely confused :(

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

0

fs is a module available when running on a Node server, not in the browser.

about 4 years ago · Juan Pablo Isaza Report

0

You need to import it as import * as fs from 'fs';. You may also have problems with fs import in the web, but that's a different issue.

More details can be found here

EDIT: The question was "Cannot import npm module". As pointed out by Michael Flores in comment and suggested in the original answer, this won't work anyway in web as fs is not module you can install - it's part of Node.JS

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!