【发布时间】:2020-07-15 14:05:41
【问题描述】:
我有一个模仿Next JS sentry (simple) example的项目的简单设置
问题是没有哨兵Enable JavaScript source fetching 功能,我无法让源地图正确报告给哨兵
例如:
使用Enable JavaScript source fetching 可以正确显示
示例(相同的错误):
这里是使用的配置文件:
// next.config.js
const { parsed: localEnv } = require("dotenv").config();
const webpack = require("webpack");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
// Package.json => "@zeit/next-source-maps": "^0.0.4-canary.1",
const withSourceMaps = require("@zeit/next-source-maps")({ devtool: "source-map" });
module.exports = withSourceMaps({
target: "serverless",
env: {
// Will be available on both server and client
// Sentry DNS configurations
SENTRY_DNS: process.env.SENTRY_DNS,
},
poweredByHeader: false,
webpack(config, options) {
config.plugins.push(new webpack.EnvironmentPlugin(localEnv));
config.resolve.plugins.push(new TsconfigPathsPlugin());
config.node = {
// Fixes node packages that depend on `fs` module
fs: "empty",
};
if (!options.isServer) {
config.resolve.alias["@sentry/node"] = "@sentry/browser";
}
return config;
},
});
src/pages/_app.tsx 和 src/pages/_error.tsx 遵循 repo 中提到的示例。
// tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"declaration": false,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"paths": {
"@src/*": ["./src/*"],
"@components/*": ["./src/components/*"],
"@services/*": ["./src/services/*"],
"@utils/*": ["./src/utils/*"]
},
"removeComments": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"sourceRoot": "/",
"strict": true,
"target": "es6",
"jsx": "preserve"
},
"exclude": [
"node_modules",
"cypress",
"test",
"public",
"out"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"compileOnSave": false
}
源地图在 CI 构建过程中上传到哨兵
使用这个脚本(在next build 和next export 之后)
configure-sentry-release.sh
#!/bin/bash
set -eo pipefail
# Install Sentry-CLI
curl -sL https://sentry.io/get-cli/ | bash
export SENTRY_ENVIRONMENT="production"
export SENTRY_RELEASE=$(sentry-cli releases propose-version)
# Configure the release and upload source maps
echo "=> Configure Release: $SENTRY_RELEASE :: $SENTRY_ENVIRONMENT"
sentry-cli releases new $SENTRY_RELEASE --project $SENTRY_PROJECT
sentry-cli releases set-commits --auto $SENTRY_RELEASE
sentry-cli releases files $SENTRY_RELEASE upload-sourcemaps ".next" --url-prefix "~/_next"
sentry-cli releases deploys $SENTRY_RELEASE new -e $SENTRY_ENVIRONMENT
sentry-cli releases finalize $SENTRY_RELEASE
有没有办法让源地图与哨兵一起工作(没有Enable JavaScript source fetching 并且不让源地图在服务器上公开可用)?
【问题讨论】:
-
你提到
Enable JavaScript source fetching,你能分享一个关于它是什么以及如何启用它的链接吗?我在github.com/UnlyEd/next-right-now/issues/28 也有类似的需求,但我从未见过你提到的这个功能 -
每个组织设置:设置 > 常规 > 允许每个项目获取 JavaScript 源代码(在“安全和隐私”下切换):项目名称 > 设置 > 常规设置 > 允许 JavaScript 源代码获取(在“客户端安全性”下切换")
-
我已经查看了您(相当不错的)项目中的源代码以供参考,但我找不到将源映射显示为第二个屏幕截图的方法(这表明错误发生在 tsx 文件中)而不启用源获取...非常感谢任何帮助以了解如何在不公开公开源映射的情况下实现它...:(
标签: typescript webpack next.js sentry