Skip to content

Stackman does not resolve filename (path) of sourcemap generated by webpack #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kerwanp opened this issue Dec 5, 2020 · 0 comments

Comments

@kerwanp
Copy link

kerwanp commented Dec 5, 2020

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]'
  },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant