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

Can't Get Started without Build Tools #542

Closed
jfavrod opened this issue Feb 13, 2020 · 3 comments · Fixed by #540
Closed

Can't Get Started without Build Tools #542

jfavrod opened this issue Feb 13, 2020 · 3 comments · Fixed by #540

Comments

@jfavrod
Copy link

jfavrod commented Feb 13, 2020

I'm trying to get started with Preact. I'm on the "Getting Started" section of the Web page. I'm trying the code sample under the heading No build tools route (below).

import { h, Component, render } from 'https://unpkg.com/preact?module';

// Create your app
const app = h('div', null, 'Hello World!');

// Inject your application into the an element with the id `app`.
// Make sure that such an element exists in the dom ;)
render(app, document.getElementById('app'));

In Chrome browser; Version 80.0.3987.100 (Official Build) (64-bit) Windows 10
I get the following error:

Uncaught TypeError: Cannot read property '__k' of null
    at E (preact.module.js?module:1)
    at index.js:8

When I click to run the code sample in REPL, I get another error:

Error: No module found for preact?module
Stack trace:
_require :1:2993
eval :6:21
Runner.execute :1:3819
Runner.execute :1:3906
unknown :0:0

I was not expecting errors.
I was expecting to use a library for creating Web components.
The no build tools route sounds great, and I'm excited to get started with Preact.

@JoviDeCroock
Copy link
Member

Hey @jfavrod

It seems that document.getElementById('app') returns null. This because the index.html you're using probably has no <div> with said id.

You can try using document.body, if you need any more resources on using a more ergonomic jsx syntax you can always look at this

@developit developit transferred this issue from preactjs/preact Feb 13, 2020
@developit
Copy link
Member

#540 should fix this.

@noel-schenk
Copy link

For anyone having a similar problem. Make sure the DOM is loaded before using preact.

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

Successfully merging a pull request may close this issue.

4 participants