Is there a polyfills.ts for `solid-start`? Or is there a way of modyfing the produced `index.html` ?

So, in the aws amplify framework there is a common bug, which all frameworks have to fix somehow: https://github.com/aws-amplify/amplify-js/issues/678 global is not defined One common solution is to add:
<script>
// aws-sdk requires global to exist
var global = global || window;
</script>
<script>
// aws-sdk requires global to exist
var global = global || window;
</script>
to the index.html, which is how I fixed this in good old solid-js. With solid-start we don't have an index.html any more and this variable needs to exist before the page is rendered (putting it into root.tsx is not enough.) Another common solution angular/svelte devs seem to use is to add the fix to a /src/polyfills.ts. Do we have something comparable in solid-start ?
1 Reply
Bersaelor
Bersaelor13mo ago
One other idea suggested was to add it to the vite.config.ts, but it didn't seem to make a difference for me
export default defineConfig({
plugins: [solid({ ssr: false }), suidPlugin()],
define: {
"global:": {},
},
});
export default defineConfig({
plugins: [solid({ ssr: false }), suidPlugin()],
define: {
"global:": {},
},
});
PS: the error occurs only with npm run dev when the site is loaded on the client. The npm run dev command succeeds fine and the error only shows in the browser console more on this: https://github.com/aws-amplify/amplify-js/issues/9639 (e.g. for Vue and react people have been able to fix it with
export default defineConfig({
plugins: [vue()],
define: {
global: {},
},
export default defineConfig({
plugins: [vue()],
define: {
global: {},
},
but that doesn't affect npm run dev for me at all in solid-start environment) The official Amplify documentation also mentions this for Vue ( https://ui.docs.amplify.aws/vue/getting-started/troubleshooting ) Where they say you have to put
<script>
window.global = window;
var exports = {};
</script>
</body>
<script>
window.global = window;
var exports = {};
</script>
</body>
into the index.html mhmm, the only thing that allowed me to continue working was to use patch-package and apply:
diff --git a/node_modules/solid-start/root/Scripts.tsx b/node_modules/solid-start/root/Scripts.tsx
index ea6dae4..19da2b5 100644
--- a/node_modules/solid-start/root/Scripts.tsx
+++ b/node_modules/solid-start/root/Scripts.tsx
@@ -23,6 +23,7 @@ export default function Scripts() {
(isDev ? (
<>
<script type="module" src="/@vite/client" $ServerOnly></script>
+ <script> var global = global || window; </script>
<script
type="module"
async
diff --git a/node_modules/solid-start/root/Scripts.tsx b/node_modules/solid-start/root/Scripts.tsx
index ea6dae4..19da2b5 100644
--- a/node_modules/solid-start/root/Scripts.tsx
+++ b/node_modules/solid-start/root/Scripts.tsx
@@ -23,6 +23,7 @@ export default function Scripts() {
(isDev ? (
<>
<script type="module" src="/@vite/client" $ServerOnly></script>
+ <script> var global = global || window; </script>
<script
type="module"
async
@thetarnav thats the only solution I found to edit the index.html so it turns out
export default defineConfig({
plugins: [solid({ ssr: false }), suidPlugin()],
define: {
global: {},
},
});
export default defineConfig({
plugins: [solid({ ssr: false }), suidPlugin()],
define: {
global: {},
},
});
worked. I just had a typo above. PS: Unfortunately, the global: {}, only works in dev, although it allows yarn build to succeed it'll trigger this.listeners.global is not a function at runtime
Want results from more Discord servers?
Add your server
More Posts
Pure client based page complaining about `window is not defined` in solid-start (No SSR needed)Back when I was just working with `solid.js` I could use `window` in my code just fine, for. pages tWhy does typescript not accept `text() && text().length === x` in solid-start?Is anyone aware why typescript complains about ```ts text() && text().length === 6 ``` in a projecUniversal renderer createElement isn't runningI'm working on a custom renderer and I can't get the createElement function to run. I'm not sure if How to read reactive state from imperative contexts (audio/music)**tl;dr:** is there any major DO NOT guideline around (constantly!) reading reactive states from fuHow to handle auto scrolling in a chat app when new message comes in?So this is an example what i currently have ```jsx const App = () => { const [messages, setMessageHow to get `onMount` to be called on the client for a server-rendered siteI've set up a new project using `solid-start` with `solid-start-aws`. Running `npm run build` createReactivity with normal functionsI try the following: `doubleCount` is using `createMemo` while `tripleCount` is a normal anonymous fSolid-js design system CSS troubleshootingI have a design-system I am building out using Kobalte. However, when I export the components none oHow to throw an Error on an unknown route?I define the content for each route like so: ```jsx return ( <Routes> <Route path={'/foo'} eleJoining SolidJS Vite app with a rest api as single appHello, I'm building a simple front end with the default SolidJS+Vite template. I call this the clien