最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - How to use puppeteer in streamdeck sdk? - Stack Overflow

programmeradmin4浏览0评论

I want to create a streamdeck plugin using Streamdeck SDK.

I created the example counter project and it works fine on Windows 11, node 23.8, Streamdeck 6.8.1.

The project is written in typescript and I wanted to add puppeteer via:

npm install puppeteer@24

Streamdeck SDK uses rollup as module bundler, and here is where I now have problems once I want to include puppeteer.

If I just want to import it and create a browser instance within my src/plugin.ts, it crashes right away on npm run watch:

import {action, KeyDownEvent, SingletonAction, WillAppearEvent} from "@elgato/streamdeck";
import * as puppeteer from "puppeteer";

    override async onKeyDown(ev: KeyDownEvent<CounterSettings>): Promise<void> {
        const browser = await puppeteer.launch(); // won't transpile, why?

        // default of example counter example

        const {settings} = ev.payload;
        settings.incrementBy ??= 1;
        settings.count = (settings.count ?? 0) + settings.incrementBy;

            await ev.action.setSettings(settings);
        await ev.action.setTitle(`${settings.count}`);
    }

On build, I get the error:

rollup v4.34.8
bundles src/plugin.ts → com.kopernikus.odoo-time-tracker.sdPlugin/bin/plugin.js...
(!) "this" has been rewritten to "undefined"

node_modules/puppeteer-core/lib/esm/puppeteer/node/ScreenRecorder.js
4:  * SPDX-License-Identifier: Apache-2.0
5:  */
6: var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
                            ^
7:     var useValue = arguments.length > 2;
8:     for (var i = 0; i < initializers.length; i++) {
...and 5 other occurrences
node_modules/puppeteer-core/lib/esm/puppeteer/api/ElementHandle.js
4:  * SPDX-License-Identifier: Apache-2.0
5:  */
6: var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
                            ^
7:     var useValue = arguments.length > 2;
8:     for (var i = 0; i < initializers.length; i++) {
...and 9 other occurrences
node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js
4:  * SPDX-License-Identifier: Apache-2.0
5:  */
6: var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
                            ^
7:     var useValue = arguments.length > 2;
8:     for (var i = 0; i < initializers.length; i++) {
...and 7 other occurrences

...and 31 other files
[!] (plugin commonjs--resolver) RollupError: node_modules/escodegen/package.json (2:10): Expected ';', '}' or <eof> (Note that you need @rollup/plugin-json to import JSON files)
node_modules/escodegen/package.json (2:10)
1: {
2:     "name": "escodegen",
             ^
3:     "description": "ECMAScript code generator",
4:     "homepage": ";,
    at Object.getRollupError (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\parseAst.js:285:41)
    at ParseError.initialise (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:15580:40)
    at convertNode (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:17474:10)
    at convertProgram (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:16717:12)
    at Module.setSource (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:18454:24)
    at ModuleLoader.addModuleSource (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:21989:13)
  [cause] RollupError: Expected ';', '}' or <eof>
      at Object.getRollupError (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\parseAst.js:285:41)
      at ParseError.initialise (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:15580:40)
      at convertNode (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:17474:10)
      at convertProgram (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:16717:12)
      at Module.setSource (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:18454:24)
      at ModuleLoader.addModuleSource (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:21989:13)


watch.onEnd $ streamdeck restart com.kopernikus.odoo-time-tracker
√ Restarted com.kopernikus.odoo-time-tracker

I want to create a streamdeck plugin using Streamdeck SDK.

I created the example counter project and it works fine on Windows 11, node 23.8, Streamdeck 6.8.1.

The project is written in typescript and I wanted to add puppeteer via:

npm install puppeteer@24

Streamdeck SDK uses rollup as module bundler, and here is where I now have problems once I want to include puppeteer.

If I just want to import it and create a browser instance within my src/plugin.ts, it crashes right away on npm run watch:

import {action, KeyDownEvent, SingletonAction, WillAppearEvent} from "@elgato/streamdeck";
import * as puppeteer from "puppeteer";

    override async onKeyDown(ev: KeyDownEvent<CounterSettings>): Promise<void> {
        const browser = await puppeteer.launch(); // won't transpile, why?

        // default of example counter example

        const {settings} = ev.payload;
        settings.incrementBy ??= 1;
        settings.count = (settings.count ?? 0) + settings.incrementBy;

            await ev.action.setSettings(settings);
        await ev.action.setTitle(`${settings.count}`);
    }

On build, I get the error:

rollup v4.34.8
bundles src/plugin.ts → com.kopernikus.odoo-time-tracker.sdPlugin/bin/plugin.js...
(!) "this" has been rewritten to "undefined"
https://rollupjs./troubleshooting/#error-this-is-undefined
node_modules/puppeteer-core/lib/esm/puppeteer/node/ScreenRecorder.js
4:  * SPDX-License-Identifier: Apache-2.0
5:  */
6: var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
                            ^
7:     var useValue = arguments.length > 2;
8:     for (var i = 0; i < initializers.length; i++) {
...and 5 other occurrences
node_modules/puppeteer-core/lib/esm/puppeteer/api/ElementHandle.js
4:  * SPDX-License-Identifier: Apache-2.0
5:  */
6: var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
                            ^
7:     var useValue = arguments.length > 2;
8:     for (var i = 0; i < initializers.length; i++) {
...and 9 other occurrences
node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js
4:  * SPDX-License-Identifier: Apache-2.0
5:  */
6: var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
                            ^
7:     var useValue = arguments.length > 2;
8:     for (var i = 0; i < initializers.length; i++) {
...and 7 other occurrences

...and 31 other files
[!] (plugin commonjs--resolver) RollupError: node_modules/escodegen/package.json (2:10): Expected ';', '}' or <eof> (Note that you need @rollup/plugin-json to import JSON files)
node_modules/escodegen/package.json (2:10)
1: {
2:     "name": "escodegen",
             ^
3:     "description": "ECMAScript code generator",
4:     "homepage": "http://github/estools/escodegen",
    at Object.getRollupError (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\parseAst.js:285:41)
    at ParseError.initialise (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:15580:40)
    at convertNode (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:17474:10)
    at convertProgram (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:16717:12)
    at Module.setSource (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:18454:24)
    at ModuleLoader.addModuleSource (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:21989:13)
  [cause] RollupError: Expected ';', '}' or <eof>
      at Object.getRollupError (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\parseAst.js:285:41)
      at ParseError.initialise (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:15580:40)
      at convertNode (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:17474:10)
      at convertProgram (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:16717:12)
      at Module.setSource (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:18454:24)
      at ModuleLoader.addModuleSource (C:\Users\philipp.kretzschmar\Documents\github\odoo-time-tracker\node_modules\rollup\dist\shared\rollup.js:21989:13)


watch.onEnd $ streamdeck restart com.kopernikus.odoo-time-tracker
√ Restarted com.kopernikus.odoo-time-tracker
Share Improve this question edited 7 hours ago k0pernikus asked 7 hours ago k0pernikusk0pernikus 66.7k77 gold badges242 silver badges361 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

In your rollup.config.mjs that should exist on your project's root, you need to add your libraries as external:

const config = {
    input: "src/plugin.ts",
    output: {
        file: `${sdPlugin}/bin/plugin.js`,
        sourcemap: isWatching,
        sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
            return url.pathToFileURL(path.resolve(path.dirname(sourcemapPath), relativeSourcePath)).href;
        }
    },
    plugins: [
       // ...
    ],
    external: ["puppeteer"]
};
发布评论

评论列表(0)

  1. 暂无评论