denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.01k stars 5.39k forks source link

Uncaught TypeError: DenoCommand is not a constructor #18281

Closed echoptic closed 1 year ago

echoptic commented 1 year ago
deno 1.31.3 (release, x86_64-unknown-linux-gnu)
v8 11.0.226.19
typescript 4.9.4

I tried running:

import puppeteer from "npm:puppeteer@19.7.5";

const browser = await puppeteer.launch({
  headless: false,
  executablePath: "/var/lib/flatpak/exports/bin/com.google.ChromeDev",
});

const page = await browser.newPage();

await page.goto("https://developer.chrome.com/");

await browser.close();

and got the error:

error: Uncaught TypeError: DenoCommand is not a constructor
    at process._kill (ext:deno_node/process.ts:207:22)
    at process.kill (ext:deno_node/process.ts:245:23)
    at pidExists (file:///home/echoptic/.cache/deno/npm/registry.npmjs.org/puppeteer-core/19.7.5/lib/esm/puppeteer/node/BrowserRunner.js:305:24)
    at BrowserRunner.kill (file:///home/echoptic/.cache/deno/npm/registry.npmjs.org/puppeteer-core/19.7.5/lib/esm/puppeteer/node/BrowserRunner.js:177:43)
    at ChromeLauncher.launch (file:///home/echoptic/.cache/deno/npm/registry.npmjs.org/puppeteer-core/19.7.5/lib/esm/puppeteer/node/ChromeLauncher.js:104:20)
    at Object.runMicrotasks (ext:core/01_core.js:406:30)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:51:14)
    at async file:///home/echoptic/git/deno-pupeteer/main.ts:3:17
GJZwiers commented 1 year ago

The problem seems to be with these lines: https://github.com/denoland/deno/blob/3b1cb8af69b0acf55c485ae3721bdb4d9322798e/ext/node/polyfills/process.ts#L64-L66

I think Deno[Deno.internal]?.nodeUnstable?.Command doesn't lead to something that has a constructor

GJZwiers commented 1 year ago
// @ts-ignore Deno[Deno.internal] is used on purpose here 
const DenoCommand = Deno[Deno.internal]?.nodeUnstable?.Command;
console.log(new DenoCommand);

1.30.0:

deno run main.ts 
Command {}

1.31.3:

deno run main.ts 
error: Uncaught TypeError: DenoCommand is not a constructor
console.log(new DenoCommand);
GJZwiers commented 1 year ago

Did a bisect and found f917d2e2c10e0a94e564a9016217e7ce27c8bbee caused this bug.

bartlomieju commented 1 year ago

Nice find @GJZwiers, it seems like an omission on my side - sorry for that. The first would be to not depend on Deno[Deno.internal] but instead directly import proper API in ext/node/polyfills/http.ts from ext:deno_http/. Would it be some you'd be interested in tackling?

GJZwiers commented 1 year ago

I have opened https://github.com/denoland/deno/pull/18289

GJZwiers commented 1 year ago

@echoptic Thanks for reporting the bug, it should be fixed in the next release, however there is another open issue when using npm:puppeteer that you would run into: https://github.com/denoland/deno/issues/17496. As an alternative I believe you can use https://deno.land/x/puppeteer instead.

Amad3eu commented 1 year ago

@echoptic What does that mean?

error: Uncaught (in promise) TypeError: Deno.Command is not a constructor
  const proc = new Deno.Command(Deno.execPath(), {
               ^
    at generate (https://deno.land/x/fresh@1.1.5/src/dev/mod.ts:137:16)
    at https://deno.land/x/fresh@1.1.5/init.ts:349:7
bartlomieju commented 1 year ago

@Amad3eu you're probably on very old version of Deno. It will work if you upgrade

Amad3eu commented 1 year ago

@bartlomieju I believe not too old, but I'm on deno 1.27.2 (release, x86_64-unknown-linux-gnu)

bartlomieju commented 1 year ago

At that point Deno.Command was unstable API and wasn't available unless --unstable flag was provided.

fortunewalla commented 1 year ago

I had the same issue today. The conda-forge https://anaconda.org/conda-forge/deno package of deno installs an older version perhaps. Deno Fresh installs using --unstable flag but doesn't run using --unstable flag.

OS: Win 10

1. Version installed from conda-forge

(deno) C:\conda>deno --version

deno 1.29.2 (release, x86_64-pc-windows-msvc)
v8 10.9.194.5
typescript 4.9.4

2. Trying to install Fresh without --unstable flage

(deno) C:\conda>deno run -A -r https://fresh.deno.dev my-project

  � Fresh: the next-gen web framework.

Let's set up your new Fresh project.

Fresh has built in support for styling using Tailwind CSS. Do you want to use this? [y/N] y
Do you use VS Code? [y/N] y
error: Uncaught (in promise) TypeError: Deno.Command is not a constructor
  const proc = new Deno.Command(Deno.execPath(), {
               ^
    at generate (https://deno.land/x/fresh@1.1.5/src/dev/mod.ts:137:16)
    at https://deno.land/x/fresh@1.1.5/init.ts:349:7

3. Trying to install Fresh using the --unstable flag makes it work.

(deno) C:\conda>deno --unstable run -A -r https://fresh.deno.dev denofresh

  � Fresh: the next-gen web framework.

Let's set up your new Fresh project.

Fresh has built in support for styling using Tailwind CSS. Do you want to use this? [y/N] y
Do you use VS Code? [y/N] y
The manifest has been generated for 3 routes and 1 islands.

Project initialized!

Enter your project directory using cd denofresh.
Run deno task start to start the project. CTRL-C to stop.

Stuck? Join our Discord https://discord.gg/deno

Happy hacking! �

4. Running without --unstable flag

(deno) C:\conda\denofresh>deno task start

Task start deno run -A --watch=static/,routes/ dev.ts
Watcher Process started.
error: Uncaught (in promise) TypeError: Deno.Command is not a constructor
  const proc = new Deno.Command(Deno.execPath(), {
               ^
    at generate (https://deno.land/x/fresh@1.1.5/src/dev/mod.ts:137:16)
    at dev (https://deno.land/x/fresh@1.1.5/src/dev/mod.ts:184:30)
    at async file:///C:/conda/denofresh/dev.ts:5:1
Watcher Process finished. Restarting on file change...

4. Running with --unstable flag

(deno) C:\conda\denofresh>deno --unstable task start

Task start deno run -A --watch=static/,routes/ dev.ts
Watcher Process started.
error: Uncaught (in promise) TypeError: Deno.Command is not a constructor
  const proc = new Deno.Command(Deno.execPath(), {
               ^
    at generate (https://deno.land/x/fresh@1.1.5/src/dev/mod.ts:137:16)
    at dev (https://deno.land/x/fresh@1.1.5/src/dev/mod.ts:184:30)
    at async file:///C:/conda/denofresh/dev.ts:5:1
Watcher Process finished. Restarting on file change...