tlianza / pigeon

Sentry Client for Cloudflare Workers
MIT License
44 stars 1 forks source link

Sentry API changed #7

Open worenga opened 4 years ago

worenga commented 4 years ago
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
crypto (imported by node_modules/crypto-js/core.js, crypto?commonjs-external)
[!] Error: 'keysToEventMessage' is not exported by node_modules/@sentry/utils/esm/index.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/@tlianza/pigeon/pigeon-backend.js (6:4)
4:     isError,
5:     isPlainObject,
6:     keysToEventMessage,
       ^
7:     normalizeToSize,
8:     SyncPromise
Error: 'keysToEventMessage' is not exported by node_modules/@sentry/utils/esm/index.js
    at error (/home/bewo/cf-repos/challenge-platform/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at Module.error (/home/bewo/cf-repos/challenge-platform/node_modules/rollup/dist/shared/node-entry.js:9820:16)
(!) Import of non-existent exports
node_modules/@tlianza/pigeon/pigeon-backend.js
 9: } from "@sentry/utils";
10: 
11: import { StackFrame, Status } from "@sentry/types"
             ^
12: import * as stacktrace from 'stack-trace'
node_modules/@tlianza/pigeon/cf-workers-sentry.js
1: import PigeonBackend from './pigeon-backend'
2: import { getCurrentHub, initAndBind, BaseClient } from '@sentry/core';
3: import { Request } from '@sentry/types';
            ^
4: 
5: export const SDK_NAME = 'cf-workers';
tlianza commented 4 years ago

How do I repro?

worenga commented 4 years ago

Create a rollup.config.js with the following:

// rollup.config.js
import nodeResolve from '@rollup/plugin-node-resolve';
import commonJS from '@rollup/plugin-commonjs';

let outfile = 'dist/worker.js';

let defaults = {
    input: 'src/main.js',
    output: {
        file: outfile,
        format: 'iife',
        compact: true,
        preferConst: true,
        sourcemap: true,
    },
    plugins: [
        commonJS({
            namedExports: {
                lru_map: ['LRUMap']
            },
            include: 'node_modules/**',
            extensions: ['.js']
          }),
        nodeResolve({})
    ]
};
export default defaults;

src/main.js:

import * as Pigeon from "pigeon";

addEventListener('fetch', event => {
    Pigeon.init({
        dsn: "https://nananananbatman@sentry.io/batman",
        event: event
      });
    /**
     * In the event of an uncaught exception, fail-open as if the  worker did not exist
     */
    event.passThroughOnException();
    event.respondWith(handleRequest(event));
});

async function handleRequest(event) {
    const request = event.request;

    Pigeon.captureException(new Error("Test123"));

    return new Response('meh')
}

error when running rollup:


src/main.js → dist/worker.js...
(!) Import of non-existent exports
node_modules/pigeon/pigeon-backend.js
 9: } from "@sentry/utils";
10: 
11: import { StackFrame, Status } from "@sentry/types"
             ^
12: import * as stacktrace from 'stack-trace'
node_modules/pigeon/cf-workers-sentry.js
1: import PigeonBackend from './pigeon-backend'
2: import { getCurrentHub, initAndBind, BaseClient } from '@sentry/core';
3: import { Request } from '@sentry/types';
            ^
4: 
5: export const SDK_NAME = 'cf-workers';
wuservices commented 1 month ago

While you should move to toucan-js, if you need a temporary quick fix for this, you can add the following to your package.json:

  "overrides": {
    "@tlianza/pigeon": {
      "@sentry/core": "5.6.1",
      "@sentry/hub": "5.6.1",
      "@sentry/minimal": "5.6.1",
      "@sentry/types": "5.6.1",
      "@sentry/utils": "5.6.1"
    }
  }

The latest Sentry version I could get to work was 5.6.1 when patching some issues temporarily on an old project.