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

bug: undici fails to load for node >=14 <14.18.0 #2467

Closed
david-luna opened this issue Nov 27, 2023 · 1 comment · Fixed by #2471
Closed

bug: undici fails to load for node >=14 <14.18.0 #2467

david-luna opened this issue Nov 27, 2023 · 1 comment · Fixed by #2471
Labels
bug Something isn't working

Comments

@david-luna
Copy link

Bug Description

apps with nodejs <14.18.0 have issues loading undici because of node: prefixed imports.

Reproducible By

Just start a new project with a simple script

package.json

{
  "name": "unidci-node-support",
  "version": "1.0.0",
  "description": "",
  "type": "commonjs",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "undici": "^5.28.1"
  }
}

and index.js

const { request } = require('undici');

request('https://httpstat.us/200')
.then((response) => {
  const {
    statusCode,
    headers,
    trailers,
  } = response;

  console.log('response received', statusCode)
  console.log('headers', headers)
  console.log('trailers', trailers)
});

Then run it

nvm use v1.4.0.0
node index.js

Expected Behavior

The script runs and logs the statusCode, headers & trailers

Logs & Screenshots

The error

internal/modules/cjs/loader.js:1017
  throw err;
  ^

Error: Cannot find module 'node:assert'
Require stack:
- /.../issues/unidci-node-support/node_modules/undici/lib/handler/RetryHandler.js
- /.../issues/unidci-node-support/node_modules/undici/index.js
- /.../issues/unidci-node-support/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1014:15)
    at Function.Module._load (internal/modules/cjs/loader.js:884:27)
    at Module.require (internal/modules/cjs/loader.js:1074:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/david/Documents/repos/issues/unidci-node-support/node_modules/undici/lib/handler/RetryHandler.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:1185:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
    at Module.load (internal/modules/cjs/loader.js:1034:32)
    at Function.Module._load (internal/modules/cjs/loader.js:923:14)
    at Module.require (internal/modules/cjs/loader.js:1074:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/.../issues/unidci-node-support/node_modules/undici/lib/handler/RetryHandler.js',
    '/.../issues/unidci-node-support/node_modules/undici/index.js',
    '/.../issues/unidci-node-support/index.js'
  ]
}

Environment

os: MacOS Sonoma 14.1.1
nodejs: 14.0.0

Additional context

Issue was found in one of our CI runs elastic/apm-agent-nodejs#3754 (comment)

@david-luna david-luna added the bug Something isn't working label Nov 27, 2023
@david-luna
Copy link
Author

A solution might be to bump the supported node version to v14.18.0

"node": ">=14.0"

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

Successfully merging a pull request may close this issue.

1 participant