edited

🤔 Expected Behavior

If you want to inline a file into the JavaScript bundle instead of reference it by URL, you can use the Node.js fs.readFileSync API to do that. The URL must be statically analyzable, meaning it cannot have any variables in it (other than __dirname and __filename).

When successful, the inlining should directly replace fs.readFileSync(...) with the asset being inlined. In the case of this example, it should replace the call with "World".

This inlining feature should work regardless of how the code is transformed, provided the transformation is not doing anything that should explicity modify the usage pattern expressed above (in short: it should work with babel-preset-env).

😯 Current Behavior

This appears to break when using Babel, or at least when using babel-preset-env with module transpilation enabled. The assets transformation does not replace the call to fs.readFileSync(...). Instead, the code is left untransformed, resulting in the following error:

Workaround

This issue can be avoided by disabling the es6-modules-amd transformation. Example .babelrc:

{
"presets": [
["env", {
"modules": false
}]
]
}

Parcel does its own module transpilation, so doing so with Babel is redundant and also seems to be the cause of this issue. One way to resolve this issue would be for Parcel to detect module transpilation in a user's .babelrc and provide instructions for disabling it. Another way would be to improve Parcel's matching of fs.readFileSync(...) such that it can succeed after module transpilation.