Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What changes should be made to make it work with custom webpack config. #47

Closed
shubhamdeodia opened this issue Oct 26, 2021 · 16 comments
Closed

Comments

@shubhamdeodia
Copy link

Is there any specific guide to make it work with custom webpack config.

When I tried it is just tries to find the bundle.js on the keycloak domain and gives 404 error.

Any suggestion, how can I fix it or using create-react-app is absolutely essential ?

@garronej
Copy link
Collaborator

Hi @shubhamdeodia,

This tool assumes you are bundling your app with Webpack (tested with 4.44.2) . It assumes there is a build/ directory at the root of your react project directory containing an index.html file and a build/static/ directory generated by webpack.

ref

To be honest I haven't tested it outside of CRA but in theory if those conditions are met it should work.
What is absolutely mandatory is for it to be an SPA.

@shubhamdeodia
Copy link
Author

shubhamdeodia commented Oct 26, 2021

@garronej

When I use create-react-app, the output in login.ftl is

<script src="${url.resourcesPath}/build/static/js/main.0f9069ba.chunk.js">

but when I use custom webpack config, the output is

<script defer="" src="static/js/bundle.62a50c2a96c578a95c88.bundle.js"></script>

any idea what might be causing this. why in my case generated theme is missing ${url.resourcesPath}

@garronej
Copy link
Collaborator

Maybe if I can see the repo...

@shubhamdeodia
Copy link
Author

@garronej : This issue got resolved, I just needed to add publicPath: '/' to my webpack config.

But I am running into another issue,


Uncaught ReferenceError: browser is not defined
    at Object.51211 (useEvt.js:32)
    at n (deepmerge.js:5)
    at Object.17330 (index.js:11)
    at n (deepmerge.js:5)
    at Object.34580 (useGlobalState.js:25)
    at n (deepmerge.js:5)
    at Object.20753 (useKcLanguageTag.js:4)
    at n (deepmerge.js:5)
    at Object.58840 (kcContextMocks.js:42)
    at n (deepmerge.js:5)

I am using webpack 5 and for some reason it is just not able to find browser and process env, even after using env plugin.

@garronej
Copy link
Collaborator

Ok.I think I can solve that

@shubhamdeodia
Copy link
Author

@garronej : Really appreciate that.

@garronej
Copy link
Collaborator

image

I dont understand... there is no mention of browser on line 32 of useEvt.js...?
Do you have an idea? can you confirm that you are using evt version: 2.0.0-beta.38 ?

@garronej
Copy link
Collaborator

Does it craches at runtime or when building?

@shubhamdeodia
Copy link
Author

shubhamdeodia commented Oct 27, 2021

@garronej

It crashes during runtime, and that browser issue came after I tried to fix this one.

image

var isWindows = process.platform === 'win32';

@garronej
Copy link
Collaborator

ok that makes a lot more sence

@garronej
Copy link
Collaborator

This error should be fixed in 4.2.2

@garronej
Copy link
Collaborator

@shubhamdeodia is it though?

@shubhamdeodia
Copy link
Author

shubhamdeodia commented Oct 28, 2021

@garronej Aplogise for my last comment, that was an issue in my code.

I will test and see if env variables are working fine now.

@garronej
Copy link
Collaborator

garronej commented Oct 28, 2021

Ok no problem, let me know if you need help.

@shubhamdeodia
Copy link
Author

It works fine, we can close this ticket, Thanks for all the help.

@ddubrava
Copy link
Contributor

ddubrava commented Jul 24, 2023

@garronej

Hi! What about these errors (Uncaught ReferenceError: process is not defined)?

Screenshot 2023-07-24 at 14 25 38 Screenshot 2023-07-24 at 14 25 45

I adjusted webpack.DefinePlugin

plugins: [
  new DefinePlugin({
    'process.env.PUBLIC_URL': JSON.stringify('/'),
  }),
]

But now it throws 404, since it tries to get src_login_KcApp_tsx.bundle.js from http://localhost:8080/ instead of http://localhost:8080/resources/mg9u1/login/keycloak-theme/build/.

If I set it to JSON.stringify(''), the same issue load script:40 GET http://localhost:8080/9047.bundle.js net::ERR_ABORTED 404 (Not Found).

garronej added a commit that referenced this issue Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants