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

Error when trying to require webpack.config.js file from path 'C:\Users\username\app-name\apps\mobile\webpack.config.js'. Error is: Error: Cannot find module 'C:\Users\username\app-name\apps\mobile\webpack.config.js' #289

Closed rob4226 closed 3 years ago

rob4226 commented 3 years ago

Hi - I cannot set breakpoints while trying to debug a NativeScript Angular project in an Nx Workspace. I keep getting the below error:

Error when trying to require webpack.config.js file from path
'C:\Users\username\app-name\apps\mobile\webpack.config.js'
Error is: Error:
Cannot find module 'C:\Users\username\app-name\apps\mobile\webpack.config.js'

If I click on the file path from the console the file opens right up so it does exist. Any ideas why this is happening?

Here is my launch.json

{
     "name": "Launch on Android Emulator",
     "type": "nativescript",
     "request": "launch",
     "platform": "android",
     "appRoot": "${workspaceRoot}/apps/mobile",
     "sourceMaps": true,
     "watch": true,
     "tnsArgs": [
         "--no-hmr",
         "--emulator"
     ]
},

Environment

rob4226 commented 3 years ago

Also get error:

Error when trying to require webpack.config.js file from path
'C:\Users\username\app-name\apps\mobile\webpack.config.js'
Error is: TypeError: host.onUnRecoverableConfigFileDiagnostic is not a function
rob4226 commented 3 years ago

I finally got vscode to find my breakpoints again. I still have the above error, but it doesn't seem to affect anything.

After a lot of messing around with things, I finally found something that magically made everything work in my Nx workspace NativeScript project. I put "sourceRoot": "." in the tsconfig.app.json compiler options and now finally the vscode debugger finds my breakpoints! sourceRoot specifies the root path for debuggers to find the reference source code.

 "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "sourceRoot": ".",
  },
// ...