parcel: fs.readFileSync - Cannot statically evaluate fs argument

πŸ› bug report

πŸŽ› Configuration (.babelrc, package.json, cli command)

{
  "your": { "config": "here" }
}

πŸ€” Expected Behavior

😯 Current Behavior

πŸ’ Possible Solution

πŸ”¦ Context

πŸ’» Code Sample

https://github.com/mytee306/marked-intro

🌍 Your Environment

Software Version(s)
Parcel latest
Node latest
npm/Yarn latest
Operating System linux mint

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 4
  • Comments: 21 (6 by maintainers)

Commits related to this issue

Most upvoted comments

just tell parcel you’re running in a node environment with the target flag

e.g. parcel app.js --target node

@codeshifu That is all it takes!

I’ll change this into a feature request as require.resolve should probably be supported as it’s pretty much what parcel currently does (without adding it explicitly).

However process.cwd() can not really be statically evaluated (at least not reliable).

Apologies if I’ve misread anything, went over this thread rather quickly.

@mytee306 Oh! Now this is something that can be improved I think. Parcel should be able to evaluate require.resolve calls statically. Then piping it into fs.readFileSync should make that work too. Maybe modify the issue or create a new one to address this?

You did this:

const markdown = require("./markdown.md");

const md = fs.readFileSync(markdown, { encoding: "UTF-8" });

Just do this:

const md = fs.readFileSync("./markdown.md", { encoding: "UTF-8" });