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

[Bug]: Puppeteer not working properly as a bundle #8044

Closed
Josehower opened this issue Feb 21, 2022 · 7 comments
Closed

[Bug]: Puppeteer not working properly as a bundle #8044

Josehower opened this issue Feb 21, 2022 · 7 comments

Comments

@Josehower
Copy link

Bug description

The last version of Puppeteer is not working using esbuild bundler (Probably any bundler).

Steps to reproduce the problem:

Reproduce on GitHub:

  1. create an issue comment
  2. Check the actions log

Reproduce Locally

  1. Clone the reproduction Repo
  2. Install dependencies
  3. Run script "start"

expected local behaviour:

The app should run with no problems when you run "dev" script and "start" script.

In advance thanks for your work on this package and the attention to this issue report.

good energy 👍👍👍👍

Puppeteer version

13.3.2

Node.js version

17.3.1

npm version

8.3.0

What operating system are you seeing the problem on?

Linux, macOS

Relevant log output

node:internal/modules/cjs/loader:933
  const err = new Error(message);
              ^

Error: Cannot find module './initialize-node'
Require stack:
- /Users/josehower/projects-upleveled/puppeteer-error-demo/upleveled-drone.mjs
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at initializePuppeteerNode (file:///Users/josehower/projects-upleveled/puppeteer-error-demo/upleveled-drone.mjs:26117:88)
    at node_modules/puppeteer/lib/cjs/puppeteer/node.js (file:///Users/josehower/projects-upleveled/puppeteer-error-demo/upleveled-drone.mjs:26144:72)
    at __require2 (file:///Users/josehower/projects-upleveled/puppeteer-error-demo/upleveled-drone.mjs:46:50)
    at node_modules/puppeteer/cjs-entry.js (file:///Users/josehower/projects-upleveled/puppeteer-error-demo/upleveled-drone.mjs:26151:27)
    at __require2 (file:///Users/josehower/projects-upleveled/puppeteer-error-demo/upleveled-drone.mjs:46:50)
    at file:///Users/josehower/projects-upleveled/puppeteer-error-demo/upleveled-drone.mjs:26157:32
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async Promise.all (index 0) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/josehower/projects-upleveled/puppeteer-error-demo/upleveled-drone.mjs'
  ]
}

Node.js v17.3.1
@Josehower Josehower added the bug label Feb 21, 2022
@OrKoN
Copy link
Collaborator

OrKoN commented Feb 21, 2022

How does esbuild handle require.resolve? In 13.3.2 we solved an issue for webpack which didn't always configure __dirname properly so it works in webpack now. I wonder if esbuild can handle require.resolve similarly?

@OrKoN
Copy link
Collaborator

OrKoN commented Feb 22, 2022

Please give 13.4.0 a try. That should work well for both esbuild and webpack.

@Josehower
Copy link
Author

I'll test it thanks.

@reesericci
Copy link

Parcel is giving me an error that it's not running in a module context even though my package.json has a type: module.

/var/home/reesericci/js/node/r1scraper/node_modules/puppeteer/lib/esm/puppeteer/node.js:16
import { initializePuppeteerNode } from './initialize-node.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module

@stale
Copy link

stale bot commented Jun 23, 2022

We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.

@stale stale bot added the unconfirmed label Jun 23, 2022
@OrKoN
Copy link
Collaborator

OrKoN commented Jun 23, 2022

I think this was likely to have been fixed with the recent fixes and changes. Please command if the issue is still happening.

@OrKoN OrKoN closed this as completed Jun 23, 2022
@mbrevda
Copy link

mbrevda commented Oct 18, 2023

still seeing this with puppeteer-core@21.3.8. To replicate:

test.ts:

import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({headless: 'new'});
const page = await browser.newPage();
await page.goto('https://www.google.com');
await browser.close();

build with:

esbuild test.ts \
  --bundle \
  --minify=false \
  --sourcemap \
  --splitting \
  --outdir=dist \
  --external:typescript \
  --platform=node \
  --out-extension:.js=.mjs \
  --format=esm \
  --banner:js=\"const require=(await import('node:module')).createRequire(import.meta.url);const __filename=(await import('node:url')).fileURLToPath(import.meta.url);const __dirname=(await import('node:path')).dirname(__filename)\"

then run:

node  --enable-source-maps  dist/test.mjs

results:

WORKING_DIR/node_modules/puppeteer-core/src/api/locators/DelegatedLocator.ts:25
export abstract class DelegatedLocator<T, U> extends Locator<U> {
                                                     ^


TypeError: Class extends value undefined is not a constructor or null
    at <anonymous> (WORKING_DIR/node_modules/puppeteer-core/src/api/locators/DelegatedLocator.ts:25:54)

Node.js v20.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment