Skip to content

static sourcemap base prefix of ../ leads to incorrect filepaths in source mapped stack traces, when output folder is more than one folder deep #1253

@iamstarkov

Description

@iamstarkov

in my case I have a GitHub action which can consists of smaller sub actions which can be used by themselves. Think of actions/cache with its actions/cache/save and actions/cache/restore. cache action builds into single dist folder but have multiple sub folders for every sub action. I do the same.

Sourcemaps work, but location mapping is one off in terms of traversing up the filesystem hierarchy. I looked into the code and it seems despite ncc programmatically supporting sourceMapBasePrefix, it is not computed at all, let alone relatively to the --output. when I add on extra, sourcemap locations start to match to the original files and I can click on the stack trace and get to an error directly from my vs code

build of the pr sub action:

~/projects/nordnet/gitops (fix/multi-document-yaml) $ npm run build:pr

> gitops@0.0.0 build:pr
> ncc build pr/action.js -o dist/pr/ --source-map

ncc: Version 0.38.3
ncc: Compiling file index.js into ESM
   0kB  dist/pr/package.json
  40kB  dist/pr/sourcemap-register.cjs
1467kB  dist/pr/index.js
1715kB  dist/pr/index.js.map
1715kB  dist/pr/index.js.map
3222kB  [1237ms] - ncc 0.38.3

before fix (notice how dist is still included into the filepath):


~/projects/nordnet/gitops (fix/multi-document-yaml) $ node --env-file=.env.test dist/pr/index.js

file:///Users/vlasta/projects/nordnet/gitops/dist/src/utils/enhanced-core.js:7
    .foo()
^
TypeError: str.foo is not a function
    at getListFromString (file:///Users/vlasta/projects/nordnet/gitops/dist/src/utils/enhanced-core.js:7:1)
    at Object.getListInput (file:///Users/vlasta/projects/nordnet/gitops/dist/src/utils/enhanced-core.js:26:1)
    at run (file:///Users/vlasta/projects/nordnet/gitops/dist/pr/action.js:35:1)

after fix:

~/projects/nordnet/gitops (fix/multi-document-yaml) $ node --env-file=.env.test dist/pr/index.js

file:///Users/vlasta/projects/nordnet/gitops/src/utils/enhanced-core.js:7
    .foo()
^
TypeError: str.foo is not a function
    at getListFromString (file:///Users/vlasta/projects/nordnet/gitops/src/utils/enhanced-core.js:7:1)
    at Object.getListInput (file:///Users/vlasta/projects/nordnet/gitops/src/utils/enhanced-core.js:26:1)
    at run (file:///Users/vlasta/projects/nordnet/gitops/pr/action.js:35:1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions