getsentry / sentry-javascript-bundler-plugins

JavaScript Bundler Plugins for Sentry
https://sentry.io
BSD 3-Clause "New" or "Revised" License
132 stars 34 forks source link

SyntaxError: Unexpected token ‘(’ when importing @sentry/webpack-plugin in custom-webpack #592

Open liangzhengcongyfd opened 2 weeks ago

liangzhengcongyfd commented 2 weeks ago

An error occurred while trying to import the @sentry/webpack-plugin in custom-webpack.config.js.

Environment

npm: v14.2.0 @angular/core: 10.2.5 webpack: 4.46.0 @angular-builders/custom-webpack: 10.0.1 @sentry/angular : 7.75.1 @sentry/tracing: 7.75.1 @sentry/webpack-plugin: 2.22.2

Steps to Reproduce

  1. "yarn add @sentry/webpack-plugin -dev"
  2. in custom-webpack.config.js: "import/require: const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');"
  3. "yarn start" or "yarn build" getting an error

Expected Result

no error

Actual Result

[error] /node_modules/@sentry/bundler-plugin-core/node_modules/minimatch/dist/cjs/ast.js:86

fillNegs() {

         ^

SyntaxError: Unexpected token '('

lforst commented 2 weeks ago

Hi, I cannot reproduce this locally with the steps you provided. Would you mind sharing a small reproduction example in the form of a repo or stackblitz? Thanks!

liangzhengcongyfd commented 2 weeks ago

Hi, I cannot reproduce this locally with the steps you provided. Would you mind sharing a small reproduction example in the form of a repo or stackblitz? Thanks!

Hi! Of course, here is the repo. You can reproduce the issue by running 'npm run build' or 'npm run start'. Thanks for your reply!

sentry-demo-repo node: v14.2.0 / npm: 6.14.4

The issue is not accurately reproduced on StackBlitz, but it does occur when running the repository locally. Here is the StackBlitz link. sentry-demo-stackblitz

lforst commented 2 weeks ago

Hi, can you try bumping your node version to version 14.6.0?

liangzhengcongyfd commented 2 weeks ago

Hi, can you try bumping your node version to version 14.6.0?

Hi, Of course, I bumped my Node.js version to 14.6.0 and reinstalled @sentry/webpack-plugin. @sentry/webpack-plugin has been bumped to version 2.22.3. However, I encountered a new issue:

[error] Error: Cannot find module 'node:path' Require stack:

Here is the repo: sentry-demo-repo node:14.6.0

BTW, is there an alternative way to solve this without bumping the Node.js version?

lforst commented 2 weeks ago

BTW, is there an alternative way to solve this without bumping the Node.js version?

Likely no. I have to admit we (I) kinda fucked up by specifying the node version range in the engines field to >= 14 which is not entirely correct. We likely won't bump it now without a major release because it runs risk of breaking CIs that check for the engines field. I think the actual minimum version required to run the plugin is node version 14.18.0, however I recommend running the latest v14 version which is 14.21.3 I believe. Node 14 is EOL for quite a while now.