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

How to include in Preact no build #283

Closed
Samuel88 opened this issue Mar 18, 2021 · 2 comments
Closed

How to include in Preact no build #283

Samuel88 opened this issue Mar 18, 2021 · 2 comments

Comments

@Samuel88
Copy link

Why adding debug line to Preact (no build) simple page this error occurs
GET https://unpkg.com/[email protected]/devtools?module net::ERR_ABORTED 404

This is the simple code

<!DOCTYPE html>
<html>
  <body>  
    <script type="module">
      // Adding this line
      import "https://unpkg.com/preact/debug/dist/debug.module.js?module";
      
      import { h, Component, render } from 'https://unpkg.com/preact/dist/preact.module.js?module';
      import htm from 'https://unpkg.com/htm/dist/htm.module.js?module';
 
      // Initialize htm with Preact
      const html = htm.bind(h);
 
      const app = html`<h1>Hello World!</h1>`;
      render(app, document.body);
    </script>
  </body>
</html>
@marvinhagemeister
Copy link
Member

This is a known error in the module resolution code of unpkg. This can't be fixed on our end.

See:

The recommended solution is to use a CDN which supports proper module resolution, like https://npm.reversehttp.com/ or https://www.skypack.dev/

<!DOCTYPE html>
<html>
  <body>  
    <div id="app"></div>
    <script type="module">
      import "https://cdn.skypack.dev/preact/debug";

      import { h, Component, render } from "https://cdn.skypack.dev/preact";
      import htm from "https://cdn.skypack.dev/htm";

      const html = htm.bind(h);

      const app = html`<h1>Hello World!</h1>`;
      render(app, document.getElementById("app"));
    </script>
  </body>
</html>

@newsch
Copy link

newsch commented Feb 5, 2023

I got this working by importing the submodule files directly, and using an import map for the preact/devtools dependency in preact/debug:

<!DOCTYPE html>
<html>
  <head>
    <script type="importmap">
      {
        "imports": {
          "htm": "https://unpkg.com/[email protected]?module",
          "preact": "https://unpkg.com/[email protected]?module",
          "preact/debug": "https://unpkg.com/[email protected]/debug/dist/debug.module.js",
          "preact/devtools": "https://unpkg.com/[email protected]/devtools/dist/devtools.module.js"
        }
      }
    </script>
  </head>
  <body>  
    <script type="module">
      // Adding this line
      import "preact/debug";
      
      import { h, Component, render } from 'preact';
      import htm from 'htm';
 
      // Initialize htm with Preact
      const html = htm.bind(h);
 
      const app = html`<h1>Hello World!</h1>`;
      render(app, document.body);
    </script>
  </body>
</html>

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