getsentry / profiling-node

The code for this repo now lives in https://github.com/getsentry/sentry-javascript/tree/develop/packages/profiling-node
MIT License
29 stars 10 forks source link

Module parse failed: Unexpected character '�' (1:0) #170

Open haydenbleasel opened 1 year ago

haydenbleasel commented 1 year ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

SDK Version

1.0.7

Link to Sentry event

No response

What environment is your node script running in?

How is your code deployed and bundled?

Standard Next.js build process running on Vercel. Here's the abstracted next.config.js:

import { withSentryConfig } from '@sentry/nextjs';

/** @type {import('next').NextConfig} */
const nextConfig = {
  async rewrites() {
    return [
      {
        source: '/api/sentry/:path*',
        destination:
          'https://{x}.ingest.sentry.io/api/{y}/envelope/',
      },
    ];
  },
  sentry: {
    hideSourceMaps: true,
    tunnelRoute: '/api/sentry',
  },
};

/** @type {import('@sentry/nextjs').SentryWebpackPluginOptions} */
const sentryWebpackPluginOptions = {
  silent: true,
};

export default withSentryConfig(
  sentryWebpackPluginOptions
);

Steps to Reproduce

Following the installation instructions in the Sentry web UI, updated my sentry.server.config.js to the following:

import * as Sentry from '@sentry/nextjs';
import { ProfilingIntegration } from '@sentry/profiling-node';

Sentry.init({
  dsn: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
  tracesSampleRate: 1.0,
  profilesSampleRate: 1.0,
  integrations: [
    new ProfilingIntegration(),
  ],
});

Deploy to Vercel which runs npm build.

Potential follow-on issue from #164

Expected Result

The build should pass.

Actual Result

19:12:21.256 |  Failed to compile.
19:12:21.256 |  
19:12:21.256 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-93.node
19:12:21.256 | Module parse failed: Unexpected character '�' (1:0)
19:12:21.256 | You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
19:12:21.257 | (Source code omitted for this binary file)
19:12:21.257 |  
19:12:21.257 | Import trace for requested module:
19:12:21.257 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-93.node
19:12:21.257 | ./node_modules/@sentry/profiling-node/lib/index.js
19:12:21.257 | ./sentry.server.config.js
19:12:21.257 | ./app/layout.tsx
19:12:21.257 |  
19:12:21.257 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-108.node
19:12:21.257 | Module parse failed: Unexpected character '�' (1:0)
19:12:21.257 | You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
19:12:21.257 | (Source code omitted for this binary file)
19:12:21.257 |  
19:12:21.257 | Import trace for requested module:
19:12:21.257 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-108.node
19:12:21.257 | ./node_modules/@sentry/profiling-node/lib/index.js
19:12:21.257 | ./sentry.server.config.js
19:12:21.258 | ./app/layout.tsx
19:12:21.258 |  
19:12:21.258 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-linux-arm64-glibc-83.node
19:12:21.258 | Module parse failed: Unexpected character '' (1:0)
19:12:21.258 | You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
19:12:21.259 | (Source code omitted for this binary file)
19:12:21.259 |  
19:12:21.259 | Import trace for requested module:
19:12:21.259 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-linux-arm64-glibc-83.node
19:12:21.259 | ./node_modules/@sentry/profiling-node/lib/index.js
19:12:21.259 | ./sentry.server.config.js
19:12:21.259 | ./app/layout.tsx
19:12:21.259 |  
19:12:21.259 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-linux-arm64-glibc-93.node
19:12:21.259 | Module parse failed: Unexpected character '' (1:0)
19:12:21.259 | You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
19:12:21.259 | (Source code omitted for this binary file)
19:12:21.259 |  
19:12:21.259 | Import trace for requested module:
19:12:21.260 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-linux-arm64-glibc-93.node
19:12:21.260 | ./node_modules/@sentry/profiling-node/lib/index.js
19:12:21.260 | ./sentry.server.config.js
19:12:21.260 | ./app/layout.tsx
19:12:21.260 |  
19:12:21.260 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-linux-arm64-glibc-108.node
19:12:21.260 | Module parse failed: Unexpected character '' (1:0)
19:12:21.260 | You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
19:12:21.260 | (Source code omitted for this binary file)
19:12:21.260 |  
19:12:21.260 | Import trace for requested module:
19:12:21.260 | ./node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-linux-arm64-glibc-108.node
19:12:21.260 | ./node_modules/@sentry/profiling-node/lib/index.js
19:12:21.260 | ./sentry.server.config.js
19:12:21.260 | ./app/layout.tsx
19:12:21.260 |  
19:12:21.260 |  
19:12:21.260 | > Build failed because of webpack errors
Clovel commented 8 months ago

Just to add to this, I also have the same issue. I tried fixing it by following the various recommendations you gave :

Failed to compile.

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-93.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-93.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-108.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-108.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-115.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-115.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-93.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-93.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-108.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-108.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

> Build failed because of webpack errors

I also use MUI components, so I got 'use client'; basically everywhere.

JesseKoldewijn commented 8 months ago

@JesseKoldewijn Your Next.js config file does not have experimental.serverComponentsExternalPackages attribute. Ref: https://github.com/getsentry/profiling-node#bundling

Ah check. Thanks, will check if that's the fix later today👌

@JesseKoldewijn Unfortunately, not work for me. Here is the verison I used "@sentry/nextjs": "7.92.0", "@sentry/profiling-node": "^1.3.5", "next": "^14.1.1-canary.25",

Are you using the node profiler in a client component by chance?

@JesseKoldewijn No, I use the default setting in my sentry.server.config file only. As the code below image

And I found there are confilts during install, because @sentry/next need a peerDependence for nextjs highest 14.0. image So maybe sentry do not fully support next14.1 right now.

As mentioned before, the package does work in Next.js 14.1.1-canary.1 and later. But without a reproduction repo and only the server config file I can't really make an educated guess on why it doesn't work in your project.

JesseKoldewijn commented 8 months ago

Just to add to this, I also have the same issue. I tried fixing it by following the various recommendations you gave :

  • Upgrade Next from 13.4.9 to 14.1.0
  • Upgrade Node to 18.17.0 (Next 14 requirement)
  • Added the following snippet to next.config.js

    {
    experimental: {
      serverComponentsExternalPackages: [
        '@sentry/profiling-node',
      ],
    },
    }```
    
    I still get the same errors as before : 
Failed to compile.

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-93.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-93.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-108.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-108.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-115.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-115.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-93.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-93.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-108.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Import trace for requested module:
../../node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-x64-108.node
../../node_modules/@sentry/profiling-node/lib/index.js
./sentry.server.config.ts
./src/app/(auth)/layout.tsx

> Build failed because of webpack errors

I also use MUI components, so I got 'use client'; basically everywhere.

Could you provide me with a reproduction repo by chance? Since I don't know where you import the profiling-node package right now.

JesseKoldewijn commented 8 months ago

To anybody with this issue past next release 14.1.1-canary.1 please check out my repo below which is a working example of the fix within nextjs I've implemented.

github.com/JesseKoldewijn/Jereko

kluu1 commented 8 months ago

I had similar issues but running Node 18, Express.js, and Webpack. I was able to get passed the Unexpected character '�' (1:0) issue by adding @sentry/profiling-node': 'commonjs @sentry/profiling-node to externals in webpack.config.js.

...
module.exports = {
  entry: './src/index.ts',
  externals: {
    '@sentry/profiling-node': 'commonjs @sentry/profiling-node',
  },
  devtool: 'inline-source-map',
  target: 'node',
  module: {
    rules: [
...

But now I'm experiencing a new error message that I have not figure out how to resolve during webpack build. Does any have any suggestions?

...
webpack://eh-replicache-api/node_modules/@sentry/profiling-node/lib/index.js:652
const DEBUG_BUILD$1 = __DEBUG_BUILD__;
^

ReferenceError: __DEBUG_BUILD__ is not defined
    at Object../node_modules/@sentry/profiling-node/lib/index.js (webpack://eh-replicache-api/node_modules/@sentry/profiling-node/lib/index.js:652:1)
    at __webpack_require__ (webpack://eh-replicache-api/webpack/bootstrap:19:1)
    at Object../src/utils/sentry/initSentry.ts (webpack://eh-replicache-api/src/utils/sentry/initSentry.ts:2:1)
    at __webpack_require__ (webpack://eh-replicache-api/webpack/bootstrap:19:1)
    at Object../src/index.ts (webpack://eh-replicache-api/src/index.ts:16:1)
    at __webpack_require__ (webpack://eh-replicache-api/webpack/bootstrap:19:1)
    at <anonymous> (webpack://eh-replicache-api/webpack/startup:4:1)
    at Object.<anonymous> (webpack://eh-replicache-api/webpack/startup:4:1)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
nguyenphusi commented 7 months ago

I've ran into a similar issue.

Tried to add

{
  experimental: {
    serverComponentsExternalPackages: [
      '@sentry/profiling-node',
    ],
  },
}

Which works as long as I don't have a use client component. I'm in

"next": "^14.1.3",
"@sentry/browser": "^7.106.1",
"@sentry/nextjs": "^7.106.0",
"@sentry/node": "^7.106.1",
"@sentry/profiling-node": "^7.106.1",

Wondering if there is a way to only enable the Profiling in the pages router and disable it in the app router?

JesseKoldewijn commented 7 months ago

I've ran into a similar issue.

Tried to add

{
  experimental: {
    serverComponentsExternalPackages: [
      '@sentry/profiling-node',
    ],
  },
}

Which works as long as I don't have a use client component. I'm in

"next": "^14.1.3",
"@sentry/browser": "^7.106.1",
"@sentry/nextjs": "^7.106.0",
"@sentry/node": "^7.106.1",
"@sentry/profiling-node": "^7.106.1",

Wondering if there is a way to only enable the Profiling in the pages router and disable it in the app router?

Are you importing the @sentry/profiling-node package inside a component which is marked with "use client"? Because this will not work due to the component also runs in the browser.

nguyenphusi commented 6 months ago

I've ran into a similar issue. Tried to add

{
  experimental: {
    serverComponentsExternalPackages: [
      '@sentry/profiling-node',
    ],
  },
}

Which works as long as I don't have a use client component. I'm in

"next": "^14.1.3",
"@sentry/browser": "^7.106.1",
"@sentry/nextjs": "^7.106.0",
"@sentry/node": "^7.106.1",
"@sentry/profiling-node": "^7.106.1",

Wondering if there is a way to only enable the Profiling in the pages router and disable it in the app router?

Are you importing the @sentry/profiling-node package inside a component which is marked with "use client"? Because this will not work due to the component also runs in the browser.

Thank you @JesseKoldewijn . Sorry for my late response as well.

We don't import @sentry/profiling-node package in any specific component. This is how we configured Sentry Profiling. We only has the import in the config files. I guess this enables the profiling for all components?

// sentry.server.config.ts
import * as Sentry from '@sentry/nextjs';
import { ProfilingIntegration } from '@sentry/profiling-node';
Sentry.init({
    profilesSampleRate: 1,
    integrations: [new ProfilingIntegration()],
});
// sentry.client.config.ts
import * as Sentry from '@sentry/nextjs';
Sentry.init({
    profilesSampleRate: 1,
    integrations: [
        new Sentry.BrowserProfilingIntegration(),
    ],
});
// next.config.mjs
import { withSentryConfig } from '@sentry/nextjs';
export default withSentryConfig({
    headers: async () => {
        return [
            {
                source: "/(.*)",
                headers: [
                    {
                        key: "Document-Policy",
                        value: "js-profiling"
                    }
                ]
            }
        ]
    },
});