Description of the issue
Stackman generate a wrong filepath when the sourcemap is generated with Webpack and using webpack:// URLs.
For example, the error triggered when using elastic-apm-node with Webpack & Typescript:
[...]
this.apmAgent.captureError(err);
[...]
error while getting callsite source context: ENOENT: no such file or directory, open '/home/kerwan/workspace/kmp-agency/kmp-flow-launcher/dist/webpack:/boilerplate-node-typescript/src/launchers/webhooks/webhook.launcher.ts'
error while getting callsite source context: ENOENT: no such file or directory, open '/home/kerwan/workspace/kmp-agency/kmp-flow-launcher/dist/webpack:/boilerplate-node-typescript/src/launchers/webhooks/abstract-webhook.launcher.ts'
error while getting callsite source context: ENOENT: no such file or directory, open '/home/kerwan/workspace/kmp-agency/kmp-flow-launcher/dist/webpack:/boilerplate-node-typescript/src/services/webpack:/boilerplate-node-typescript/src/app.ts'
error while getting callsite source context: ENOENT: no such file or directory, open '/home/kerwan/workspace/kmp-agency/kmp-flow-launcher/dist/webpack:/boilerplate-node-typescript/src/services/webpack:/boilerplate-node-typescript/src/app.ts'
For example, the sourcemap URL for webpack://boilerplate-node-typescript/./src/launchers/abstract-launcher.ts
is resolved to /home/kerwan/workspace/kmp-agency/kmp-flow-launcher/dist/webpack:/boilerplate-node-typescript/src/launchers/webhooks/webhook.launcher.ts
when it should be /home/kerwan/workspace/kmp-agency/kmp-flow-launcher/src/launchers/webhooks/webhook.launcher.ts.
Steps to reproduce
Setup a project with webpack, typescript and ts-loader with the following configuration:
package.json:
{
[...]
"devDependencies": {
"ts-loader": "^8.0.11",
"typescript": "^4.1.2",
"webpack": "^5.10.0",
"webpack-cli": "^4.2.0",
},
"dependencies": {
"stackman": "^4.0.1"
}
[...]
}
webpack.config.js:
const path = require('path')
const {NODE_ENV} = process.env
module.exports = {
mode: NODE_ENV,
target: 'node',
devtool: 'source-map',
entry: path.resolve(__dirname, 'src/app.ts'),
output: {
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /.ts$/,
include: /src/,
loader: 'ts-loader'
}
]
},
resolve: {
extensions: ['.ts', '.js', '.json']
},
}
With this configuration it will generate in the folder dist the file main.js and the sourcemap main.js.map.
Workaround
Temporarily, we have changed the devtool config in webpack to use relative paths without the namespace:
module.exports = {
output: {
path: path.resolve(__dirname, 'dist'),
devtoolFallbackModuleFilenameTemplate: '../[resource-path]',
devtoolModuleFilenameTemplate: '../[resource-path]'
},
}
Description of the issue
Stackman generate a wrong filepath when the sourcemap is generated with Webpack and using
webpack://URLs.For example, the error triggered when using
elastic-apm-nodewith Webpack & Typescript:For example, the sourcemap URL for
webpack://boilerplate-node-typescript/./src/launchers/abstract-launcher.tsis resolved to
/home/kerwan/workspace/kmp-agency/kmp-flow-launcher/dist/webpack:/boilerplate-node-typescript/src/launchers/webhooks/webhook.launcher.tswhen it should be
/home/kerwan/workspace/kmp-agency/kmp-flow-launcher/src/launchers/webhooks/webhook.launcher.ts.Steps to reproduce
Setup a project with
webpack,typescriptandts-loaderwith the following configuration:package.json:
{ [...] "devDependencies": { "ts-loader": "^8.0.11", "typescript": "^4.1.2", "webpack": "^5.10.0", "webpack-cli": "^4.2.0", }, "dependencies": { "stackman": "^4.0.1" } [...] }webpack.config.js:
With this configuration it will generate in the folder
distthe filemain.jsand the sourcemapmain.js.map.Workaround
Temporarily, we have changed the devtool config in webpack to use relative paths without the namespace: