hectorm/otpauth

This does not work in Zos and IBMi environments.

xufudong2012 opened this issue ยท 12 comments

import * as crypto from "node:crypto";

This does not work in Zos and IBMi environments.

2023-03-02 10_17_52

want to know why use this rather than import * as crypto from "crypto"

The reason for importing node:crypto instead of crypto is that with Node.js it is now preferable to use the node: prefix to distinguish the built-in modules from the rest. There is no longer a supported version of Node.js that does not include this feature.

I'm not familiar with z/OS environments, are you trying to run this code in Node.js or is it an alternative that implements the Node.js APIs?

If Node.js, what version is it?

I was trying to run this code in Node.js. the version is v16.17.0

@hectorm , thanks for your response. So maybe don't need to distinguish the other same name library, there is no same library(crypto) on NPM, if exist, we can though another method such as alias.

How about change it by 'import * as crypto from "crypto" ' that can solve the ZOS and Power platform issue ?

Node.js 16.17.0 supports importing the crypto module with the node: prefix, so if it does not work in your case, it is possible that the problem is not related to the Node.js version.

Can you confirm if this command returns the same result as me?

$ node -e 'console.log(process.versions.node, typeof require("node:crypto"))'
16.17.0 object

It is possible that removing the node: prefix will fix this particular error, but I'm not familiar with z/OS and don't know if more problems can arise in that environment. Also, I like to adhere to best practices, and these days it is recommended that all built-in modules are imported with the node: prefix, and since there is no supported version of Node.js that does not include this feature, I'm wary of reversing this change.

I would like to understand where the problem is coming from in order to find the best possible solution. Could you share with me a minimal project that reproduces this bug in your environment?

bash-4.3$ node -e 'console.log(process.versions.node, typeof require("node:crypto"))'
internal/modules/cjs/loader.js:905
throw err;
^

Error: Cannot find module 'node:crypto'
Require stack:

  • /proj/mvd/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at [eval]:1:43
    at Script.runInThisContext (vm.js:134:12)
    at Object.runInThisContext (vm.js:311:38)
    at internal/process/execution.js:77:19
    at [eval]-wrapper:6:22
    at evalScript (internal/process/execution.js:76:60) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [ '/proj/mvd/[eval]' ]
    }

//without prefix
bash-4.3$ node -e 'console.log(process.versions.node, typeof require("crypto"))'
14.17.2 object

Ubuntu and Z/os have the same issue.
2023-03-06 10_21_41

At first you said you were using Node.js v16, but in subsequent posts I see lower versions.

These versions are no longer officially supported and in fact cannot import modules with the node: prefix. I'm sorry, but the only thing I can recommend is to upgrade to a newer version of Node.js.

Node.Js V14 still is a LTS version at least for now , the lower version we posted is the result that we test on different platform
I am curious about that this Prefix-Only Core Modules was introduced on Node.Js v18,
For backwards compatibility purposes, it does not force to use prefix except the new defined modules.

I reviewed lots of libraries- big download, they are still use the old style to import native module .

The latest version of Node.js v14 is currently supported, and this project's CI is testing against it. Node.js 14.18.0 has received a backport for importing modules with the node: prefix, but you are using an older version without official support.

got it, thank you.