denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
2.99k stars 596 forks source link

Deno Node API throwing assertion error about wrong Node Version though installed #1402

Closed Noxdor closed 2 years ago

Noxdor commented 2 years ago

Describe the bug

When I'm trying to import a module using the Deno Node API, I get an assertion error, that the current nodejs version is not sufficient. Though it should be. Running which node I get .../.nvm/versions/node/v14.17.6/bin/node which is higher than the required 8.0.0. It tells me though, that the current nodejs version is 1.14.0. Where does this check happen?

Steps to Reproduce

  1. Try to use the node-opcua module in a simple deno file.
import { createRequire } from "https://deno.land/std@0.111.0/node/module.ts"

const require = createRequire(import.meta.url)
const { OPCUAServer } = require("node-opcua")

console.log(OPCUAServer)
  1. Run the code.
deno run --unstable --allow-read --allow-env opc.ts
  1. Get the error message.
warning node-opcua: Required nodejs version >=8.0.0 not satisfied with current nodejs version v1.14.0.
error: Uncaught AssertionError
    Error.captureStackTrace(this, stackStartFn || stackStartFunction);
          ^
    at new AssertionError (https://deno.land/std@0.111.0/node/assertion_error.ts:529:11)
    at toNode (https://deno.land/std@0.111.0/node/assert.ts:58:15)
    at assert (https://deno.land/std@0.111.0/node/assert.ts:76:3)
    at Object.<anonymous> (file:///home/lennart/programming/hermos/backend/node_modules/node-opcua-crypto/dist/source/crypto_utils.js:157:1)
    at Module._compile (https://deno.land/std@0.111.0/node/module.ts:153:36)
    at Object.Module._extensions..js (https://deno.land/std@0.111.0/node/module.ts:1094:10)
    at Module.load (https://deno.land/std@0.111.0/node/module.ts:132:34)
    at Function._load (https://deno.land/std@0.111.0/node/module.ts:398:14)
    at Module.require (https://deno.land/std@0.111.0/node/module.ts:118:21)
    at require (https://deno.land/std@0.111.0/node/module.ts:1149:16)

Expected behavior

Logging the imported object successfully.

Environment

Noxdor commented 2 years ago

So it seems the assertion error comes from the node package (node-opcua). It checks for a correct node version and instead reads the deno version as node version (see my original post above and compare the error message and my installed deno version). Anyone having an idea how to trick the module into believing me the correct node version is installed?

bartlomieju commented 2 years ago

Thanks for @Noxdor, this problem is due to the fact that we when we shim process.version we use current Deno version for this purpose. I believe this is wrong and will lead to more problem down the road. Quick and easy fix would be to hard code this value to the latest Node LTS version, so right now that would be 16.11.1.

CC @kt3k @AaronO what do you think?