nativescript-community / nativescript-vscode-extension

A Visual Studio Code Extension for NativeScript
https://www.nativescript.org/visual-studio-code
Apache License 2.0
82 stars 32 forks source link

Unable to debug applications when output.library in webpack.config.js is set #263

Closed rosen-vladimirov closed 4 years ago

rosen-vladimirov commented 4 years ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

Describe the bug In case you set output.library in the webpack.config.js file, the application does not hit breakpoints in VSCode anymore.

To Reproduce

  1. $ tns create myApp --js
  2. $ cd myApp
  3. Now edit webpack.config.js and add library: "myLib" in the config.output section:
    output: {
    library: "myLib",
            pathinfo: false,
            path: dist,
            sourceMapFilename,
            libraryTarget: "commonjs2",
            filename: "[name].js",
            globalObject: "global",
            hashSalt
        },
  4. Now open the project with VSCode and add NativeScript configuration for debug.
  5. Run the Launch on Android or Launch on iOS configuration.
  6. After application is running and debugger is attached, try to set a breakpoint in main-view-model.js's onTap handler. The breakpoint will be red dot in case it is successfully placed and grayed out otherwise. We expect to have red dot, but it is gray.
  7. Now tap the button - breakpoint should be hit, but it is not

Expected behavior Debugging to work.

Sample project

Additional context The problem is in the parsing of the generated source maps - in case you parse them, the source URLs in them are in the following format:

"webpack://myLib/./main-view-model.js"

while we expect them to start with webpack:///

Workaround Add the following lines in your launch.json:

"sourceMapPathOverrides": {
    "webpack:///*": "${workspaceRoot}/<app dir name>/*",
    "webpack://<library name>/*": "${workspaceRoot}/<app dir name>/*"
}

Where <app dir name> is the name of your app folder as defined in nsconfig.json (probably app or src) and <library name> is the value of output.library from webpack.config.js.

For example, for the project created as described in the steps to reproduce, the snippet is:

"sourceMapPathOverrides": {
    "webpack:///*": "${workspaceRoot}/app/*",
    "webpack://myLib/*": "${workspaceRoot}/app/*"
}
rosen-vladimirov commented 4 years ago

Acceptance criteria:

endarova commented 4 years ago

There is an issue on Mac OS: Error when trying to require webpack.config.js file from path 'Users/test/Documents/webpack/js1/webpack.config.js'. Error is: Error: Cannot find module 'Users/test/Documents/webpack/js1/webpack.config.js'