Replies: 1 comment
-
We have similar issues with __filename. Any solutions here? Ends with "Uncaught (in promise) ReferenceError: __filename is not defined" |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
We have a react native library that uses Expo to load its fonts. This involves using a require statement load in our font assets:
const [fontsLoaded, fontsError] = useFonts({ 'MyFont': require('../../../assets/fonts/MyFont.otf')});
Our parcel config is set to copy the
otf
font files:{ "extends": "@parcel/config-default", "transformers": { "*.otf": [ "@parcel/transformer-raw" ], "*.{ts,tsx}": [ "@parcel/transformer-typescript-tsc" ], "*.{js,mjs,jsx,cjs}": [ "@parcel/transformer-js", "@parcel/transformer-react-refresh-wrap" ] } }
When we run our parcel command
parcel build --no-scope-hoist --no-cache
the font files are packaged correctly and we can see them in our dist folder. However the reference to the font file now includes a__filename
variable that is not set.parcelRequire.register("4UyaP", function(module, exports) { module.exports = new URL("MyFont.a8c0586f.otf", "file:" + __filename).toString(); });
As this
__filename
variable is not set anywhere it causes an error when we try to use our library.Is there a way to configure parcel that would copy the files and not add in the
__filename
variable?Or, if we do need to set the variable, where should we add it to our set up so that it gets picked up by the parcel build step?
Many thanks!
Beta Was this translation helpful? Give feedback.
All reactions