Skip to content
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

Unable to set breakpoints using ES Module syntax #613

Open
MichaelGoberling opened this issue Nov 2, 2022 · 6 comments
Open

Unable to set breakpoints using ES Module syntax #613

MichaelGoberling opened this issue Nov 2, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@MichaelGoberling
Copy link
Contributor

Describe the bug
Breakpoints can't be set in VSCode when debugging actions written in ES Module syntax.

Expected behavior
Breakpoints can be set and stopped at by VSCode debugger with actions written in ES Module syntax.

Additional context

  • Potential limitation of wskdebug
@MichaelGoberling MichaelGoberling added the bug Something isn't working label Nov 2, 2022
@moritzraho
Copy link
Member

@MichaelGoberling MichaelGoberling self-assigned this Nov 3, 2022
@MichaelGoberling
Copy link
Contributor Author

MichaelGoberling commented Nov 3, 2022

Here's a hacky workaround for now:

  • Nest your action's index.js in a src folder inside your action folder
  • Edit app.config.yaml to point to new action code location
  • Add a package.json to new src folder
{
    "type": "module"
}
  • Add a webpack-config.js to your action folder:
module.exports = { 
    devtool: 'source-map' 
}
  • Add source map location to the debugger config for your action in .vscode/launch.json:
"resolveSourceMapLocations": [
  "${workspaceFolder}/dist/application/actions/<application>/<actionName>-temp/*.js"
]    
  • Modify debugger runtime args for your action to pass transpiled file in .vscode/launch.json:
"runtimeArgs": [
  "sequence_test/first",
  "${workspaceFolder}/dist/application/actions/<application>/<actionName>-temp/index.js",
  "-v",
  "--disable-concurrency",
  "--kind",
  "nodejs:16"
]

Note: The steps modifying .vscode/launch.json will have to be run on each subsequent invocation of aio app run as this commands regenerates this config and will overwrite the changes made above

@MichaelGoberling
Copy link
Contributor Author

MichaelGoberling commented Nov 3, 2022

I believe what we want is to generate the source map for ESM actions during build time and when we run aio app run, we want to add the source map as part of the launch configuration for the ESM action and modify the debugger runtime args to point to the transpiled file. Thoughts?

@moritzraho
Copy link
Member

moritzraho commented Nov 3, 2022

Nice workaround + investigation. Yes I think that's the approach we should follow. Would need some testing to make sure debugging works as expected with the transpiled file + source maps

@bstopp
Copy link

bstopp commented Nov 4, 2022

The debugger will still have to allow the root package.json file to have type: module specified.

When i add it to mine, so that i can get the unit tests to work, the debugger results in:

Cannot load module ... Error [ERR_REQUIRE_ESM]: require() of ES Module ... from /nodejsAction/runner.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /code/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Maybe the transpiled files should end in cjs?

@MichaelGoberling MichaelGoberling removed their assignment Nov 15, 2022
@aiojbot
Copy link
Collaborator

aiojbot commented Dec 2, 2022

JIRA issue created: https://jira.corp.adobe.com/browse/ACNA-1894

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants