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

"Uncaught ReferenceError: React is not defined" when using Router #19

Open
kee-oth opened this issue May 22, 2021 · 3 comments
Open

"Uncaught ReferenceError: React is not defined" when using Router #19

kee-oth opened this issue May 22, 2021 · 3 comments

Comments

@kee-oth
Copy link

kee-oth commented May 22, 2021

I'm getting Uncaught ReferenceError: React is not defined when running the below code. I'm not sure why React is in the equation here. What am I missing about how this works?

import { Router, pathIntegration } from '@rturnq/solid-router';

const Root = () => {
  return (
    <Router integration={pathIntegration()}>
      <h1>App</h1>
    </Router>
  );
};

export default Root;

Versions:

"@rturnq/solid-router": "^0.2.6",
"solid-js": "^0.26.5",

Thanks!

@rturnq
Copy link
Owner

rturnq commented May 23, 2021

You code looks fine. Are you using Vite?

Assuming this is the case. Vite uses esbuild to pre-build dependencies as an optimization. By default esbuild treats any JSX it encounters as React and converts it to React.createElement calls. Vite excludes dependencies it knows have JSX but only does so by looking at the extension of the entry file which doesn't work in this case. It does have a workaround though by manually excluding the library using the optimizeDeps.exclude config option.

// vite.config.js
export default defineConfig({
  ...
  optimizeDeps: {
    exclude: ['@rturnq/solid-router'],
  }
});

@kee-oth
Copy link
Author

kee-oth commented May 23, 2021

I am using Vite and your suggested fix works!

Is this in the docs somewhere? I just took a look and wasn't able to find this information.

Thank you!

@rturnq
Copy link
Owner

rturnq commented May 23, 2021

There is now ffa31c8

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

2 participants