-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
global window properties are not loaded when loading an external script #8534
Comments
Hey! Yes, the entry point (index.html) is determined based on the In this case, that should work though. You mention that putting the |
Good point, I reviewed it, and indeed placing the html in the project root, in the sandbox I provided, doesn't solve the issue. So I isolated it further (in the sandbox I provided), and it seems the Does this make any sense? |
Ah! That makes sense, there's a discrepancy with our bundler resolving and the one that our static server does. If you open https://d7q7sp.csb.app/index1.html, then you should see that the script tags do work. The parcel template is a bit hacky, I think that's why we see this behaviour. In this case, the frontend bundler (the one running in the browser) resolves the Meanwhile, our static server does not check Does that make sense? There are some intricacies from how this was implemented sprinkled around here 😅 . |
🐛 bug report
Description of the problem
When loading external script, some global window properties should be added.
Specifically, after loading 'mocha' and 'chai' scripts, the following properties should exist: 'window.mocha' and 'window.chai'.
This works well in a normal environment.
However, when running the same code in a codesandbox, these properties are missing from the global 'window' variable.
It seems that the chai.js and mocha.js script files are downloaded (in the network tab of the browser debugger).
I isolated the problem to the location of 'index.html' file. When it is under the 'src' folder, this problem persists.
When it is under the project root folder, this problem doesn't occur.
How has this issue affected you? What are you trying to accomplish?
My goal is to create a codesandbox to demonstrate Mocha capability of running in a browser, as specified here:
https://mochajs.org/#running-mocha-in-the-browser
To Reproduce
Create a Node environment with a simple html, sourcing the following script:
Then, in another script, try to access
window.chai
In a non-codesandbox environment, you will get a structure.
In codesandbox, you will get
undefined
.So, when trying to access
window.chai.expect
, the following Type Error occurs:The reason is that
chai
is undefined inwindow
Link to sandbox:
link to sandbox
Your Environment
The text was updated successfully, but these errors were encountered: