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

fix: fix sourcemap errors with node v18 #2596

Merged
merged 1 commit into from
Mar 5, 2022
Merged

Conversation

trentm
Copy link
Member

@trentm trentm commented Mar 4, 2022

Recent node v18 turned on an implementation of fetch() by default.
The '[email protected]' dep used for sourcemap handling incorrectly
uses the presence of fetch to decide it is in a browser env.

This change inlines the load-source-map dep so we can update it to
use the beta [email protected] which includes a fix.

Fixes: #2589

Recent node v18 turned on an implementation of `fetch()` by default.
The '[email protected]' dep used for sourcemap handling incorrectly
uses the presence of `fetch` to decide it is in a browser env.

This change inlines the load-source-map dep so we can update it to
use the *beta* [email protected] which includes a fix.

Fixes: #2589
@trentm trentm requested a review from astorm March 4, 2022 18:49
@trentm trentm self-assigned this Mar 4, 2022
@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Mar 4, 2022
@apmmachine
Copy link
Contributor

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-03-04T18:50:03.254+0000

  • Duration: 22 min 34 sec

Test stats 🧪

Test Results
Failed 0
Passed 242233
Skipped 0
Total 242233

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run module tests for <modules> : Run TAV tests for one or more modules, where <modules> can be either a comma separated list of modules (e.g. memcached,redis) or the string literal ALL to test all modules

  • run benchmark tests : Run the benchmark test only.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

Copy link
Contributor

@astorm astorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting -- I was under the impression that fetch would still need a --experimental-fetch to run in Node 18. I wonder if that's an oversight in a pre-release build or a signal to a chance of plans.

Regardless -- I see in this PR we've downloaded a local copy of load-source-map at version 2.0.0 that's identical to the load-source-map distribution. This module has source-map as a dependency.

Then we've updated the version of the source-map package we're using to 0.8.0-beta.0 in order to force our local copy of load-source-map to use this version of source-map.

FWIW, I did a quick check and tried using the following combination in package.json

    "source-map": "0.8.0-beta.0",
    "load-source-map": "^2.0.0",    

and NPM appeared to do the right thing -- but I presume the approach in this PR gives us a little more certainty and control. Approving.

@trentm
Copy link
Member Author

trentm commented Mar 4, 2022

I was under the impression that fetch would still need a --experimental-fetch to run in Node 18. I wonder if that's an oversight in a pre-release build or a signal to a chance of plans.

It is intentional: nodejs/node#41811

FWIW, I did a quick check and tried using the following combination in package.json

    "source-map": "0.8.0-beta.0",
    "load-source-map": "^2.0.0",    

and NPM appeared to do the right thing - ...

That doesn't work for what we need:

% git diff
diff --git a/package.json b/package.json
index d503b3f0..b0316121 100644
--- a/package.json
+++ b/package.json
@@ -95,6 +95,7 @@
     "http-headers": "^3.0.2",
     "is-native": "^1.0.1",
     "load-source-map": "^2.0.0",
+    "source-map": "0.8.0-beta.0",
     "lru-cache": "^6.0.0",
     "measured-reporting": "^1.51.1",
     "monitor-event-loop-delay": "^1.0.0",
     
% npm install
...

% npm ls source-map
[email protected] /Users/trentm/tmp/apm-agent-nodejs
├─┬ @babel/[email protected]
│ └── [email protected]
├─┬ @babel/[email protected]
│ └─┬ @babel/[email protected]
│   └── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ └─┬ [email protected]
│   └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│   └─┬ [email protected]
│     └─┬ [email protected]
│       └─┬ [email protected]
│         └── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│   └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   └─┬ [email protected]
│     └── [email protected]
└── [email protected]

% ls node_modules/load-source-map/node_modules
source-map

In this case load-source-map will use its own version 0.7.3 of source-map.

@trentm trentm merged commit 94c1f11 into main Mar 5, 2022
@trentm trentm deleted the trentm/fix-sourcemap-node-v18 branch March 5, 2022 00:46
@trentm
Copy link
Member Author

trentm commented Mar 7, 2022

FYI: [email protected] was recently released which includes the PR fix I had posted. We could go back to using that. However, I hesitate right now because the author bumped the min supported Node version to v12 (which is reasonable). The bump to Node v12 was currently only for devDependencies, so 3.0.1 still works with our current min node v8.6. There is no guarantee that stays that way for the 3.x series.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

node v18.0.0-nightly20220222c071bd581a's fetch() breaks current sourcemap support
3 participants