I am trying to serverside render a react page using Django. The server-side rendering is working fine for normal react components. The project is using parcel to auto-build javaScript files so that Django could render them. This is the command I am using to compile react to Js.
"scripts": { "watch": "parcel watch src/index.tsx --public-url /assets/" }
I am new to the parcel, So sorry for the poor framing of the problem and/or any wrong terminology.
The problem comes whenever I try to import an assets component in my assets folder into my react components. The import statement in my react code is working fine but I am getting an error in the import statements of the assets folder telling the file path for import is wrong. Here is the below screenshot of the issue.
enter image description here
@parcel/core: Failed to resolve 'assets/theme/base/typography' from './src/assets/theme/index.js'
C:profitionalBRAVOServerassetssrcassetsthemeindex.js:23:24
22 | import breakpoints from "assets/theme/base/breakpoints";
> 23 | import typography from "assets/theme/base/typography";
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24 | import boxShadows from "assets/theme/base/boxShadows";
25 | import borders from "assets/theme/base/borders";
Done in 689.72s.
C:profitionalBRAVOServerassets>yarn parcel watch src/index.tsx
yarn run v1.22.19
$ C:profitionalBRAVOServerassetsnode_modules.binparcel watch src/index.tsx
× Build failed.
@parcel/core: Failed to resolve 'assets/theme/base/breakpoints' from './src/assets/theme/index.js'
C:profitionalBRAVOServerassetssrcassetsthemeindex.js:22:25
21 | import colors from "assets/theme/base/colors";
> 22 | import breakpoints from "assets/theme/base/breakpoints";
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23 | import typography from "assets/theme/base/typography";
24 | import boxShadows from "assets/theme/base/boxShadows";
The issue with this is that I am not able to figure out how to adjust the assets files properly in the react parcel project configurations so that I don’t need to change any of the assets paths.
The is my file paths in the project where:
Server is the Django project root folder
- assets (Has all react code for SSR)
- src
- assets(the folder I am trying to import)
- theme
-index(file that is causing the error)
- theme
- assets(the folder I am trying to import)
- src
enter image description here
enter image description here
The error is not caused by just one asset import, it’s going to be caused by all the import statements in the src/assets folder. I already tried to change all the file paths in the assets folder that are causing the issue but it’s too cumbersome. What can I do to solve this issue in this React parcel project?
,parcelrc file
{
"extends": ["@parcel/config-default"],
"resolvers": ["@parcel/resolver-glob", "..."]
}
jsconfig.json file
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"*": ["public/src/*"]
}
}
}
Thank you for taking the time to help me with this issue. If you need any additional information please ask in the comments section.
I am expecting to solve this import statment issues by changing the assets folder path in config files so that I don’t have to change all the import statment paths in src/assets folder.
Nithin Kamineni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.