Parcel: fs.readFile is not a function

Created on 8 Dec 2017  路  7Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

After getting started with your Step by Step tutorial I got stuck while trying to import the node file system. If I try to use fs to read a file, it seems that parcel can't get access to the node module.

import fs from 'fs';

console.log(fs);

console.log(fs) just gives me an empty function back.

馃帥 Configuration (.babelrc, package.json, cli command)

{
  "name": "parcel-sandbox",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "babel-preset-env": "^1.6.1",
    "leaflet": "^1.2.0",
    "parcel-bundler": "^1.0.3"
  }
}

馃敠 Context

My goal is just to get a basic setup of parcel running.

| Software | Version(s)
| ---------------- | ----------
| Parcel | 1.0.3
| Node | 9.2.0
| npm/Yarn | 1.3.2
| Operating System | MacOS 10.13.1

Most helpful comment

No, I still have the same issue and switched to another bundler until nodes fs module is fully implemented.

All 7 comments

this is probably because "fs" is a node-package and does not work and should not be imported to client.

fs.readFileSync should work, the async functions aren't implemented. see docs here: https://parceljs.org/assets.html

@fdnklg I had the same problem锛孒ow did you solve it ?

@fdnklg Did you solve it eventually?

No, I still have the same issue and switched to another bundler until nodes fs module is fully implemented.

You can solve it by using synchronous functions instead of async functions...

It doesn't actually work for my use case, as there are pseudo files on conditional paths, which should only get read at runtime. I switched to another bundler, because I believe this is out-of-scope for parcel.

Was this page helpful?
0 / 5 - 0 ratings