Styled components not working with ReactJS library as an esm module #8892
-
In my PHP app, I use a javascript ESM module made out of React Library (library target). I have tested different functionalities and they all work but when I try to use
I have also used to the module
Not sure why this happens, as I am unable to get to any solution. It seems like there is some dependency for the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi, Any help with this will be valuable. Is this a known bug ? |
Beta Was this translation helpful? Give feedback.
-
It seems like the code was encountering a module resolution issue with Parcel when using Styled Components in a React-based library within the main PHP application. This error might be related to the "process" module, which is typically a Node.js global object and not available in the browser environment. To fix this issue, these are the steps I followed: Install the browser-process-hrtime and process packages:
Create a shim.js file in your React library's source folder:
Import this shim.js file at the very top of your React library's entry point:
Update your package.json to include the browser field:
This solution adds a browser-compatible version of the process module, and the browser-process-hrtime package provides a browser-compatible version of the process.hrtime function. After following these steps, rebuild the project and check the browser console |
Beta Was this translation helpful? Give feedback.
It seems like the code was encountering a module resolution issue with Parcel when using Styled Components in a React-based library within the main PHP application. This error might be related to the "process" module, which is typically a Node.js global object and not available in the browser environment.
To fix this issue, these are the steps I followed:
Install the browser-process-hrtime and process packages:
npm install browser-process-hrtime process
Create a shim.js file in your React library's source folder:
Impo…